Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何扩展WPF路径控制_C#_Wpf_Path_Shape - Fatal编程技术网

C# 如何扩展WPF路径控制

C# 如何扩展WPF路径控制,c#,wpf,path,shape,C#,Wpf,Path,Shape,在我的windows窗体应用程序中,它承载一个WPF复合控件作为空调系统的内部显示。在此图中,每条气体管道和流体管道由路径控件表示。我们希望这些路径对象的颜色(使用Path.Fill)表示压力警报状态,例如低警报、中警报或高警报 我们的部分代码如下所示: <local:UC_Line_1 Margin="27.728,16.486,39.219,36.308" DataContext="{Binding Pipe1Alert}"/> <local:UC_Line_2 Margi

在我的windows窗体应用程序中,它承载一个WPF复合控件作为空调系统的内部显示。在此图中,每条气体管道和流体管道由路径控件表示。我们希望这些路径对象的颜色(使用Path.Fill)表示压力警报状态,例如低警报、中警报或高警报

我们的部分代码如下所示:

<local:UC_Line_1 Margin="27.728,16.486,39.219,36.308" DataContext="{Binding Pipe1Alert}"/>
<local:UC_Line_2 Margin="21.172,15.322,33.218,6.876"  DataContext="{Binding Pipe2Alert}"/>
<local:UC_Line_3 Margin="46.907,0,31.36,26.178" DataContext="{Binding Pipe3Alert}"/>
<local:UC_Line_4 Margin="0,11.939,20.842,13.835" DataContext="{Binding Pipe4Alert}"/>
这种方法的问题是 1.路径是一个密封的类。WPF不允许我扩展它。 2.即使假设我可以从路径控制扩展,我如何添加一个新属性“AlertState”以用于原始UC_Line_1代码中显示的数据触发器


感谢并问候。

有一个简单的解决方案。使用单个控件
UC\u行
,并向其添加属性
PathData
。然后可以从控件内绑定到该属性:

<Path x:Name="FL_2" Stretch="Fill" 
    Data="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=PathData}">

谢谢McGarnagle,您提出的解决方案确实为我提供了使用PathData的能力。
<local:UC_Line_Path AlertState="{Binding Pipe1Alert.AlertState}" Data="M20.167,0 L24.167,0 24.167,28.924 44,28.924 44,32.924 24.167,32.924 20.167z"/>
<local:UC_Line_Path AlertState="{Binding Pipe2Alert.AlertState}" Data="M20.167,0 L24.167,0 24.167,28.924 44,28.924 44,32.924 28.924 z"/>
<local:UC_Line_Path AlertState="{Binding Pipe3Alert.AlertState}" Data="M20.167,0 L24.167,0 24.167,28.924 44,28.924 44,32.924 24.167,32.924 20.167,32.924 0,32.924 0,28.924 z"/>
<local:UC_Line_Path AlertState="{Binding Pipe4Alert.AlertState}" Data="M20.167,0 L24.167,0 24.167,28.924  20.167,32.924 0,32.924 0,28.924 20.167,28.924 z"/>
<Path x:Name="FL_2" Stretch="Fill" 
    Data="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=PathData}">
<local:UC_Line Margin="27.728,16.486,39.219,36.308" 
               DataContext="{Binding Pipe1Alert}"
               PathData="M20.167,0 L24.167,0 24.167,28.924 44,28.924 44,32.924 24.167,32.924 20.167,32.924 0,32.924 0,28.924 20.167,28.924 z"
/>
public class UC_Line : UserControl
{
    public static readonly DependencyProperty PathDataProperty =
        DependencyProperty.Register("PathData", typeof(Geometry), typeof(UC_Line), null);
    public Geometry PathData
    {
        get { return (Geometry)GetValue(PathDataProperty); }
        set { SetValue(PathDataProperty, value); }
    }

    // ... etc
}