控件中有一个布尔型DependencyProperty
,名为IsRunning
,它指示控件正在执行某些操作。我想创建一个Style
,该控件集的Visibility
设置为可见如果IsRunning == true
,或者折叠如果IsRunning == false
。将依赖属性绑定到样式中的可见性
控制可以在页面中使用这样的:
<TheControl Style="{StaticResource MyStyle}" IsRunning="{Binding CategoryListLoaded}"/>
,我试过的风格(我也有试过TemplatedParent而不是自我没有运气):
<Style x:Key="MyStyle" TargetType="TheControl" >
<Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self}, Path=IsRunning, Converter={StaticResource BoolToVisibilityConverter}}"/>
</Style>
通过以上代码我得到一个XamlParseException。 我不想在页面中设置可见性,我想用样式来控制可见性,因为我有很多这些控件,只有一种样式。
您不能在IsRunning属性的PropertyChangedCallback中设置控件的可见性吗?还是有其他原因使用风格? –
我从.dll引用此控件,因此我无权访问该代码。 –
“TheControl”是一个'UserControl'还是别的? – McGarnagle