Select to view content in your preferred language

Accessing a xaml Style  resourcs in C#

808
3
09-12-2012 04:22 PM
NathalieNeagle
Regular Contributor
I tweaked the FeatureDataGrid Style by adding a button.  I set the button in my resources (style for FeatureDataGrid).  I added a new button and set it the Visibility to Collapsed
  <Button x:Name="SeeRelateButton" Margin="5,0" Click="SeeRelateButton_Click">
                                            <TextBlock Margin="5" Text="See Relate" VerticalAlignment="Center" Visibility="Collapsed"/>
                                        </Button>


Now I have some code in my C# and I want to make that button visible when something happens in my C# page.  How would I do this

MyFDG.Resources["SeeRelateButton"].Visibility = Visibility.Visible; ????????????????

Thanks
Nathalie
0 Kudos
3 Replies
NathalieNeagle
Regular Contributor
Any ideas?
0 Kudos
HyrumErnstrom
Regular Contributor
Templates are a self contained inside the Control and can't be accessed easily by the code outside the control.

The brute force way is to use the VisualTreeHelper, but this isn't the right way.

The right why is to implement an Attached DepenencyProperty that binds the visibility via ViewModel Object or create a class that inherits the FeatureDataGrid that has a Depenency Property for the buttons visibility. That why you can bind it all together.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
MyFDG.Resources["SeeRelateButton"].Visibility = Visibility.Visible; ????????????????


As Hyrum noticed, you can't change a Template this way.

But if your Handler 'SeeRelateButton_Click' is called, why not just change the visibility in the Handler (by using the 'sender ' argument)?
0 Kudos