Reputation: 3324
There is a boolean DependencyProperty
in a control, named IsRunning
, which indicates that the control is doing something. I want to create a Style
with Visibility
of this control set to Visible if IsRunning == true
, or Collapsed if IsRunning == false
.
The control can be used in a page like this:
<TheControl Style="{StaticResource MyStyle}" IsRunning="{Binding CategoryListLoaded}"/>
and the style I tried (I too have tried TemplatedParent instead of Self without luck):
<Style x:Key="MyStyle" TargetType="TheControl" >
<Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self}, Path=IsRunning, Converter={StaticResource BoolToVisibilityConverter}}"/>
</Style>
With the above code i get a XamlParseException. I don't want to set the visibility in the page, I want to control the visibility with the style, because I have many of these controls and only one style.
Upvotes: 1
Views: 94
Reputation: 6142
doing in Style binding is still not supported I think... but there is a good old article that has a helper as a solution! Read about it here: http://blogs.msdn.com/b/delay/archive/2010/11/10/the-taming-of-the-phone-new-settervaluebindinghelper-sample-demonstrates-its-usefulness-on-windows-phone-7-and-silverlight-4.aspx
Upvotes: 2
Reputation: 554
Since IsRunning is a bool, have you tried adding visibility straight to the control
<TheControl Style="{StaticResource MyStyle}" IsRunning="{Binding CategoryListLoaded}" Visibility="{Binding CategoryListLoaded, Converter={StaticResource BoolToVisibilityConverter}}"/>
Upvotes: 1