0

適切な ViewModel にバインドされたユーザー コントロールがあります。ViewModel.Graph プロパティにバインドされたこのコントロールにGraphLayout ( Graph#を使用) があります。

<graph:ProductGraphLayout Graph="{Binding Path=Graph}" />

ProductVertex を含む多数の VertexControl がこのレイアウトに配置されます。コンテンツは DataTemplate で表され、Style を使用してテーマが適用されます。

<DataTemplate x:Key="VertexTemplate" DataType="{x:Type graph:ProductVertex}">
    <TextBlock Text="{Binding Path=ID, Mode=OneWay}" />
</DataTemplate>
<Style TargetType="{x:Type graphsharp:VertexControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type graphsharp:VertexControl}">
                <Border>
                    <Border.Style>
                        <Style TargetType="{x:Type Border}">
                            <Setter Property="BorderBrush" Value="#6695C4" />
                            <Setter Property="BorderThickness" Value="2" />
                        </Style>
                    </Border.Style>
                    <ContentPresenter Content="{TemplateBinding Vertex}" ContentTemplate="{StaticResource VertexTemplate}" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

IsCurrent など、ProductVertex プロパティに基づいてコンテナー (VertexControl) のスタイルを変更するにはどうすればよいですか?

4

2 に答える 2

1

私がデータ構造を理解している限り、のを使用してオブジェクトProductVertexを使用できます。たとえば、ValueConverterを使用して、頂点オブジェクトに応じて境界線の色を変更できます。ControlTemplateVertexControl

<ControlTemplate TargetType="{x:Type graphsharp:VertexControl}">
    <Border>
        <Border.Style>
            <Style TargetType="{x:Type Border}">
                <Setter Property="BorderBrush" Value="{TemplateBinding Vertex.IsCurrent, Converter={StaticResource YourBoolToColorConverter}" />
                <Setter Property="BorderThickness" Value="2" />
            </Style>
        </Border.Style>
        <ContentPresenter Content="{TemplateBinding Vertex}" ContentTemplate="{StaticResource VertexTemplate}" />
    </Border>
</ControlTemplate>
于 2012-06-20T06:37:18.023 に答える
1

私はそれを達成する方法を自分で管理したようです:

<DataTemplate x:Key="VertexTemplate" DataType="{x:Type graph:ProductSubstitutionVertex}">
    <TextBlock Text="{Binding Path=ID, Mode=OneWay}">
        <TextBlock.Style>
            <Style TargetType="TextBlock">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsCurrent}" Value="true">
                        <Setter Property="Background" Value="#EDF2F6" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TextBlock.Style>
    </TextBlock>
</DataTemplate>
于 2012-06-20T06:46:45.237 に答える