I want a data template to display the usual things except I want to remove (make hidden) certain UI elements when the user is in certain windows. I was wondering how I can get access to a data template to edit it like that. I already know how to get access to the object that the template is displaying (the binding data source), just need the template.
My Add new Machine Window:
private void OnInit(object sender, RoutedEventArgs e)
{
this.DataContext = new MachineItem("Type your description here",
MachineTypeEnum.Computer, "1.1.1.1", "1.1.1.1", 4, null, ((GUIApp)Application.Current).CurrentMachineGroup,
BordersStyle.Blue);
//Below are 2 lines that sudo represent what I am trying to do.
var template = this.DataContext as TheTemplateIWant; //Wrong
template.DeleteButton.Visibility = Visibility.Hidden; //I don't need a delete button on something I am trying to add
}
I know another way I could do this is to change a property of the "MachineItem" object and then make a DataTrigger in the template to edit the UI based on this property (I could use a bool), but this seems a bit hackish because the MachineItem object is representing data and shouldn't have to keep track of which window it is in. I'm also open to other ways other than editing in OnInit(), as long as it is good practice