我正在尝试基于datatrigger切换contentpresenter的内容.我想在contentpresenter.content中显示usercontrol,如果我有值集,或者我需要显示错误消息.但是我的datatrigger上的绑定失败声明找不到该属性.我无法获取datacontext继承数据触发器检查.我可以通过使用注释掉的代码使其工作.但我很困惑为什么它不能正常工作.
<ContentPresenter.Style>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Content" Value="{Binding UC}"/>
<Style.Triggers>
<!--<DataTrigger Binding="{Binding DataContext.HasValue,RelativeSource={RelativeSource AncestorType={x:Type ContentPresenter}}}" Value="false">
<Setter Property="Content" Value="No preview"/>
</DataTrigger>-->
<DataTrigger Binding="{Binding HasValue}" Value="false">
<Setter Property="Content" Value="No value"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentPresenter.Style>
</ContentPresenter>
Run Code Online (Sandbox Code Playgroud) 我希望将一个timepan属性绑定到一个文本块,这似乎是在这篇文章的帮助下解决的
现在我想在数据为null时隐藏StringFormat.如果我使用带有stringformat的mutibinding并且如果我的数据为null,那么stringformat只显示一个":"
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}:{1}">
<Binding Path="MyTime.Hours" TargetNullValue={x:Null}/>
<Binding Path="MyTime.Minutes" TargetNullValue={x:Null}/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)
如果数据为空,我怎么能隐藏":"
有什么方法可以让我只能在文本块上显示一个Bound字符串的第一个字符..?
例如;如果我绑定'男',我的文本块应该只显示'M'.....
我正在寻找构建一个打开列表,就像在窗口上下文菜单中,为图像文件.所以我怎么能得到与文件类型相关的所有程序的列表?

我目前有以下XAML:
<TextBox Text="" x:Name="textFeedbackFeedback"
Margin="11.593,0,29.307,42.96" TextWrapping="Wrap"
VerticalContentAlignment="Top" VerticalAlignment="Bottom"
Height="92.08" AcceptsReturn="True" VerticalScrollBarVisibility="Visible"/>
Run Code Online (Sandbox Code Playgroud)
我尝试过使用很多变种:
if(textFeedbackFeedback.text == "")
if(textFeedbackFeedback.text == null)
if(textFeedbackFeedback.text == string.Empty)
if(string.IsNullOrEmpty(textFeedbackFeedback.Text))
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,它不会停在那里并继续,好像那里有数据,有人可以帮助我在这里.
谢谢.
wpf ×6
binding ×2
c# ×2
data-binding ×1
datatrigger ×1
registry ×1
string ×1
textblock ×1
textbox ×1