Reputation: 10055
For the sake of simplicity say i have this control called DetailArea
<UserControl x:Class="DetailArea">
<Grid>
<CustomDataControl x:Name="MyDataControl" />
</Grid>
</UserControl>
In another control i use my DetailArea
<UserControl x:Class="Display">
<Grid>
<DetailArea />
</Grid>
</UserControl>
CustomDataControl in the DetailArea control has a public Visibility dependency property like all UI elements property that i want to be able to set to Hidden.
How can i do this from the Display control?
Edit: I cannot modify the DetailArea wpf or code as it's in another all which I don't control.
Upvotes: 2
Views: 443
Reputation: 1201
According to your Answers in the Comments, i suggest you to apply a Style which only affects the mentioned Control. Something like this
<UserControl x:Class="Display">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type CustomDataControl}" BasedOn="{StaticResource KeyOfCustomDataControlStyle}">
<Setter Property="Visibility" Value="Hidden"/>
</Style>
</Grid.Resources>
<DetailArea />
</Grid>
</UserControl>
Note: This is just a Pseudo Code, please modifiy it to match your Environment.
Note2: The BasedOn="{StaticResource KeyOfCustomDataControlStyle}"
is optional.
Edit
I've removed the x:Key="MakeInvisible"
because the style may be not be applied correctly, details see here (Credits to @Jack).
Upvotes: 1
Reputation: 169200
I cannot modify the DetailArea wpf or code as it's in another all which I don't control.
Then you can't set a property of the CustomDataControl
using XAML.
What you should do is to add add dependency property to the DetailArea
class and bind the Visibility
property of the CustomDataControl
to this one. You can then set this property in the Display
UserControl
:
<DetailArea Visibility="Collapsed" />
If you can't modify DetailsArea
for some reason, you will have to set the property programmatically, e.g:
detailArea.MyDataControl.Visibility = Visibility.Collapsed;
Upvotes: 0