绑定到另一个控件时,ControlTemplate DataTrigger无法更新

时间:2020-05-20 17:29:32

标签: wpf xaml wpf-controls datatrigger

我一直在创建一个自定义控件,该控件包括一个位于Datagrid顶部的组面板。

我有一个水印文本块,一旦通过“隐藏代码”将子代添加到PART_GroupPanel中,该文本块应会折叠。

以下代码是ControlTemplate的一部分,我将在应用程序中多次使用它。

<!--Watermark Textblock-->
<TextBlock Text="Drag &amp; Drop Column to Group." Foreground="{DynamicResource FirstThemeBrush}" FontFamily="Calibri" Margin="8,0,0,0" VerticalAlignment="Center">
    <TextBlock.Style>
        <Style TargetType="TextBlock">
            <Setter Property="Visibility" Value="Collapsed"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=PART_GroupPanel, Path=Children.Count}" Value="0">
                    <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>
<!--Panel-->
<StackPanel x:Name="PART_GroupPanel" Margin="0,1,0,2" Orientation="Horizontal">
    <StackPanel.Resources>
        <Style TargetType="Button" BasedOn="{StaticResource RoundedButtonStyle}">
            <Setter Property="Padding" Value="15,5"/>
            <Setter Property="Margin" Value="0,0,0,0"/>
        </Style>
        <Style TargetType="Path">
            <Setter Property="Width" Value="5"/>
            <Setter Property="Height" Value="8"/>
            <Setter Property="Margin" Value="5,0"/>
            <Setter Property="Fill" Value="{DynamicResource FirstThemeBrush}"/>
            <Setter Property="Stretch" Value="Fill"/>
            <Setter Property="Data" Value="M 0 6 L 2 0 L 25 25 L 2 50 L 0 42 L 16 25 L 0 6 Z"/>
        </Style>
    </StackPanel.Resources>
</StackPanel>

通过后台代码添加项目后,DataTrigger不会更新和折叠文本块。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

要解决此问题,请改用$datasource = "server=(local);database=master;trusted_connection=true" $connection = New-Object System.Data.SQLClient.SQLConnection($connectionString) $connection.open() Write-Host "SQL Connection Opened" $SQLScalarCommand = @" SELECT Cast((SELECT BulkColumn FROM OPENROWSET(BULK'c:\XMLClass\Shakespeare\Hamlet\hamlet.xml',SINGLE_CLOB) as myalias) as XML).query( ' <html><body> { for $act in //ACT return $act } </body></html> ') "@ #Write-Host $SQLScalarCommand $Command = New-Object System.Data.SQLClient.SQLCommand $Command.Connection = $connection $Command.CommandText = $SQLScalarCommand $SQLResult = $Command.ExecuteScalar().ToString() Write-Host ("Result=$SQLResult") $connection.close() 。由于其布局使用ItemsControl,因此它的功能基本上像StackPanel

StackPanel