我有以下用于显示文件的xaml。如果文件存在于本地计算机上,则它是可点击的超链接,否则只是普通的文本块。
<TextBlock Visibility="{Binding FileName, Converter={StaticResource fileExistsConverter}}" Grid.Column="2" TextDecorations="Underline" Margin="5,0,0,0" Foreground="Black" Text="{Binding FileName}" />
<TextBlock Margin="5,0,0,0" Grid.Column="2" Visibility="{Binding FileName, Converter={StaticResource fileDoesntExistConverter}}">
<Hyperlink Click="Hyperlink_Click_1">
<TextBlock Text="{Binding FileName}" />
</Hyperlink>
</TextBlock>
这适用于页面加载,但在窗口打开时不会更新,例如下载其中一个列出的文件。我将如何触发刷新以便XAML可以交换样式?
答案 0 :(得分:1)
资源:
<Style x:Key="SwapTemplateStyle" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<TextBlock />
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsExist}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Hyperlink>
<TextBlock />
</Hyperlink>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
在您看来:
<ContentControl Style="{StaticResource SwapTemplateStyle}" />