Reputation: 127
I just want to create a textbox, which appears only if certain conditions are met! What i want is that, if the conditions are met the textbox should appear.
If the conditions are not met, then it should not be visible (not just changing the visibility of the textbox to collapsed),i.e there should not be an empty place too.
How can i do this??
Upvotes: 0
Views: 251
Reputation: 2778
I think there is no need to create TextBox dynamically. you should manage it by creating TextBox in xaml and TextBox Visibility. When you create our TextBox in xaml remember that Height should be default of TextBox. Here is the sample
<TextBox x:Name="txtVisible" Visibility="Collapsed"/>
if(Condition==met)
txtVisible.Visibility=Visibility.Visible;
else
txtVisible.Visibility=Visibility.Collapsed;
Upvotes: 1
Reputation: 3331
Add a textbox inside the grid object like
Grid grid=new Grid(){Height=60,Width=100};
Textbox tBox=new Textbox(){Text="Sample",Visibility=Visibility.Collapsed};
grid.Children.Add(tBox);
now conditions
if(Condition==true)
{
tBox.Visibility=Visibility.Visible;
}
else
{
tBox.Visibility=Visibility.Collapsed;
}
Upvotes: 1
Reputation: 1
You can use panels I think. Put something under to panel, put panel and then put textbox on it. And make panel invisible by default. If conditions are met u can make panel visible by code
Upvotes: -1
Reputation: 1202
XAML provides rich data binding mechanism for MVVM pattern. You have to:
INotifyPropertyChanged
in ViewModel
PropertyChanged
event of INotifyPropertyChanged
fired in setter in ViewModel
with data type of TextBox
visibilityTextBox
Then, changing this property somewhere automatically leads to changing TextBox
state
Upvotes: 1