How to active UserControl outside the wrapper?
I met a Focus related problem in UserControl:
Suppose we have a UserControl like this:
<UserControl x:Class="_20130826.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<ListBox>
<ListBoxItem>
<TextBlock Text="text1" />
</ListBoxItem>
<ListBoxItem>
<TextBlock Text="text2" />
</ListBoxItem>
<ListBoxItem>
<TextBlock Text="text3" />
</ListBoxItem>
<ListBoxItem>
<TextBlock Text="text4" />
</ListBoxItem>
</ListBox>
</StackPanel>
</UserControl>
And the MainWindow.xaml like this:
<Window x:Class="_20130826.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:temp="clr-namespace:_20130826"
Title="MainWindow">
<StackPanel>
<Button Content="Deactive UserControl" />
<StackPanel>
<Button Name="Button1" Content="Active UserControl" />
<ContentControl>
<temp:UserControl1 />
</ContentControl>
</StackPanel>
</StackPanel>
</Window>
Step 1: Click text1 TextBlock inside UserControl, and default the
background changes to deeper.
Step 2: Click 'Deactive UserControl' button, so the text1 background turns
to lighter.
Step 3: Click 'Active UserControl' button, then ...
I want the text1 background changed to deeper, which means the UserControl
has been focused/actived.
How can I achieve this?
No comments:
Post a Comment