mardi 24 février 2015

Binding foreground color from trigger

I would like to have Path as a content in CheckBox and I want Fill color to be Foreground color of that checkbox. On top of that I need to change path data when the checkbox is checked.


When the checkbox where this style is applied is loaded path is displayed, but when I click it the path disappears. I know it's there because I can see that checkbox has different width when I check it, but path is not visible. For some reason when I check this with snoop everything seems to be fine. Also when I get rid of binding and choose for example Black as a color for Fill for my paths in triggers then it works.



<Style TargetType="CheckBox">
<Setter Property="Content">
<Setter.Value>
<Path Stretch="Uniform" Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}}" Data="F1 M 22.17,36.4216L 25.3369,36.4216L 25.3369,31.6711C 25.3369,24.6745 31.0087,19.0027 38.0053,19.0027C 45.0019,19.0027 50.6737,24.6745 50.6737,31.6711L 50.6737,36.4216L 53.841,36.4216L 53.8411,57.008L 22.17,57.008L 22.17,36.4216 Z M 45.9231,31.6711C 45.9231,27.2982 42.3782,23.7533 38.0053,23.7533C 33.6324,23.7533 30.0875,27.2982 30.0875,31.6711L 30.0875,36.4216L 45.923,36.4216L 45.9231,31.6711 Z "/>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Content">
<Setter.Value>
<Path Stretch="Uniform" Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}}" Data="F1 M 52.2573,19.0027C 58.3793,19.0027 63.3422,23.9655 63.3422,30.0875L 63.3422,31.6711L 58.5915,31.6711L 58.5915,30.0875C 58.5915,26.5892 55.7556,23.7533 52.2573,23.7533C 48.759,23.7533 45.9231,26.5892 45.9231,30.0875L 45.923,34.8377L 49.0902,34.8377L 49.0902,55.4242L 19.0029,55.4242L 19.0029,34.8378L 41.1724,34.838L 41.1724,30.0875C 41.1724,23.9655 46.1353,19.0027 52.2573,19.0027 Z M 31.6711,50.6737L 36.4217,50.6737L 35.1052,44.0911C 35.8857,43.7018 36.4217,42.8956 36.4217,41.9642C 36.4217,40.6523 35.3583,39.5889 34.0464,39.5889C 32.7346,39.5889 31.6711,40.6523 31.6711,41.9642C 31.6711,42.8956 32.2072,43.7018 32.9876,44.0911L 31.6711,50.6737 Z "/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Content">
<Setter.Value>
<Path Stretch="Uniform" Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type CheckBox}}}" Data="F1 M 22.17,36.4216L 25.3369,36.4216L 25.3369,31.6711C 25.3369,24.6745 31.0087,19.0027 38.0053,19.0027C 45.0019,19.0027 50.6737,24.6745 50.6737,31.6711L 50.6737,36.4216L 53.841,36.4216L 53.8411,57.008L 22.17,57.008L 22.17,36.4216 Z M 45.9231,31.6711C 45.9231,27.2982 42.3782,23.7533 38.0053,23.7533C 33.6324,23.7533 30.0875,27.2982 30.0875,31.6711L 30.0875,36.4216L 45.923,36.4216L 45.9231,31.6711 Z "/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>


Any ideas how to make it work and why it's not working in the first place?





Aucun commentaire:

Enregistrer un commentaire