views:

28

answers:

1

I'm working on a user control right now in which I have a path as part of the control. There are 3 possible paths I might want to display based on the values of certain data. To determine which Path I want to use, I have a value converter that takes in the data and returns a number to represent which of the paths I should use.

My first thought was to just use the property changed callback from the two dependency properties I am getting data from, but those callbacks must be static and the XAML code is always non-static.

My second attempt is to now use datatriggers with the value converter described above. Below is the code I have.

               <Path x:Name="path" Stretch="Fill" Width="111.75" Height="118.718" Data="F1M205.917,103.0088C189.333,93.8108,170.128,88.9998,150,88.9998C129.873,88.9998,110.584,93.8108,94.167,102.8408L116.1,144.2508L150,208.7178L183.9,144.2508z" Canvas.Left="0" Canvas.Top="0">
                <Path.Resources>
                    <Style TargetType="{x:Type Path}">
                        <Style.Triggers>
                            <DataTrigger Value="-1">
                                <DataTrigger.Binding>
                                    <MultiBinding Converter="{StaticResource ToleranceRangeTypeChecker}">
                                        <Binding ElementName="UserControl" Path="ToleranceZoneLowerBound" />
                                        <Binding ElementName="UserControl" Path="ToleranceZoneUpperBound" />
                                    </MultiBinding>
                                </DataTrigger.Binding>
                                <Setter Property="Data" Value="F1M205.917,103.0088C189.333,93.8108,170.128,88.9998,150,88.9998C129.873,88.9998,110.584,93.8108,94.167,102.8408L116.1,144.2508L150,208.7178L183.9,144.2508z" />
                                <Setter Property="Width" Value="111.75" />
                                <Setter Property="Height" Value="118.718" />
                                <!--<Setter Property="Canvas.SetLeft"-->
                            </DataTrigger>
                            <DataTrigger Value="0">
                                <DataTrigger.Binding>
                                    <MultiBinding Converter="{StaticResource ToleranceRangeTypeChecker}">
                                        <Binding ElementName="UserControl" Path="ToleranceZoneLowerBound" />
                                        <Binding ElementName="UserControl" Path="ToleranceZoneUpperBound" />
                                    </MultiBinding>
                                </DataTrigger.Binding>
                                <Setter Property="Data" Value="F1M150,88.9998C129.873,88.9998,110.584,93.8108,94.167,102.8408L150,208.7178C150,208.7178,150,114.157407529625,150,88.9998z" />
                                <Setter Property="Width" Value="55.917" />
                                <Setter Property="Height" Value="118.718" />
                                <!--<Setter Property="Canvas.SetLeft"-->
                            </DataTrigger>
                            <DataTrigger Value="1">
                                <DataTrigger.Binding>
                                    <MultiBinding Converter="{StaticResource ToleranceRangeTypeChecker}">
                                        <Binding ElementName="UserControl" Path="ToleranceZoneLowerBound" />
                                        <Binding ElementName="UserControl" Path="ToleranceZoneUpperBound" />
                                    </MultiBinding>
                                </DataTrigger.Binding>
                                <Setter Property="Data" Value="F1M205.917,103.0088C189.333,93.8108 170.128,88.9998 150,88.9998 150,113.365662567029 150,208.7178 150,208.7178L183.9,144.2508z" />
                                <Setter Property="Width" Value="111.75" />
                                <Setter Property="Height" Value="118.718" />
                                <!--<Setter Property="Canvas.SetLeft"-->
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>

Another thought I had was to instead actually have 3 different paths and use setters to change the visibility of each, but I think that having one path and changing it's propertise would be more logical. I would also prefer one path because my goal would be to eventually animate between the paths rather than have them change instantly.

Thanks!

+2  A: 

You can get the instance by casting the sender parameter in the property change callbacks.

SLaks
thanks! I feel dumb because I should have known this. I think it eluded me because in the callbacks you have "DependencyObject d" instead of "object sender", but casting works just as nicely.
brandon