Hello,
Welcome to Microsoft Q&A!
Based on your scenario, you don't need to remove the button from the template. My suggestion is you could just change the visibility of the button to achieve the same behavior- make the button disappear. This will also be more easy to control in case you want to bring the button back.
To reach this goal, you will need to implement the INotifyPropertyChanged interface and add a new bool property in the data model. Like the following code:
public class Test :INotifyPropertyChanged
{
private string _showedName { get; set; }
private bool _buttonVisibility { get; set; }
public string showedName
{
get { return _showedName; }
set
{
_showedName = value;
RaisePropertyChanged("showedName");
}
}
public bool buttonVisibility
{
get { return _buttonVisibility; }
set
{
_buttonVisibility = value;
RaisePropertyChanged("buttonVisibility");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
And in the Xaml, you need to bind the visibility property.
TextBox x:Name="tbxProjectName" Text="{Binding showedName, UpdateSourceTrigger=Explicit,Mode=TwoWay}" Grid.Column="0" HorizontalAlignment ="Stretch" BorderThickness="0"
Button x:Name="btnProjectItemButton" Content=".." Grid.Column="1" HorizontalAlignment="Right" Margin="5,0,0,0" Visibility="{Binding buttonVisibility,Mode=TwoWay}"
After that, when you change the bool value of the data model, the button will disappear.