How to refresh the textbox text when tabs are Changed in WPF
Posted
by
StonedJesus
on Stack Overflow
See other posts from Stack Overflow
or by StonedJesus
Published on 2012-10-22T12:15:21Z
Indexed on
2012/10/23
11:01 UTC
Read the original article
Hit count: 195
Well in my WPF application I am using Tab Control which has around 5 tabs. The view of each tab is a user control which I add via a tool box.
Main Xaml File:
<Grid>
<TabControl Height="Auto" HorizontalAlignment="Stretch" Margin="0" Name="tabControl1" VerticalAlignment="Stretch" Width="Auto">
<TabItem Header="Device Control" Name="Connect">
<ScrollViewer Height="Auto" Name="scrollViewer1" Width="Auto">
<my:ConnectView Name="connectView1" />
</ScrollViewer>
</TabItem>
<TabItem Header="I2C">
<ScrollViewer Height="Auto" Name="scrollViewer2" Width="Auto">
<my1:I2CControlView Name="i2CControlView1" />
</ScrollViewer>
</TabItem>
<TabItem Header="Voltage">
<ScrollViewer Height="Auto" Name="scrollViewer3" Width="Auto">
<my2:VoltageView Name="voltageView1" />
</ScrollViewer>
</TabItem>
</TabControl>
</Grid>
If you notice each view ie.e Connect
, I2C
and Voltage
is a user control which has a view, viewmodel and model class :)
Each of these views have set of textboxes in their respective xaml files.
Connect.xaml:
<Grid>
<Textbox Text="{Binding Box}", Name="hello" />
// Some more textboxes
</Grid>
I2c.xaml:
<Grid>
<Textbox Text="{Binding I2CBox}", Name="helI2c" />
// Some more textboxes
</Grid>
Voltage.xaml:
<Grid>
<Textbox Text="{Binding VoltBox}", Name="heVoltllo" />
// Some more textboxes
</Grid>**
By default I have set the text of these textboxes to some value. Lets say "12" "13" "14" respectively in my view model classes. My main requirement is to set the text of these textboxes present in each user control to get refreshed when I change the tab.
Description:
Lets say Connect View is displayed: Value of Textbox is 12 and I edit it and change it to 16. Now I click on I2C tab and then I go back to Connect tab, I want the textbox value to get refreshed back to the initial value i.e. 12.
To be precise, is their a method called visibilitychanged() which I can write in all my user control classes, where I can set the value of these Ui components whenever tabs are changed?
Please help :)
© Stack Overflow or respective owner