none
关于自定义控件获取焦点的问题 RRS feed

  • 问题

  • 我想我写的自定义控件可以获取焦点,但是里面的控件就可以获取焦点,如何做到啊?

    就是想把那个Grid x:Name="gdmain" 在获取焦点时,底色变色。

    <UserControl x:Class="UUCManage.UUCClient.Resources.UnfinishedControl"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" 
                 Height="50" Width="180">
        <Grid x:Name="gdMain">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="35"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="50"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Path x:Name="phOrderType" Stretch="Fill" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Stroke="{x:Null}" Fill="#000000" Margin="2,5,5,5" VerticalAlignment="Center" HorizontalAlignment="Center"
                                              Data="F1 M 314.693,597.383L 125.88,408.565L 251.755,408.565L 251.755,188.264L 377.635,
                                              188.264L 377.635,408.565L 503.509,408.565M 566.448,-0.550598L 62.9387,-0.550598C 28.1813,-0.550598 2.03451e-005,
                                              27.6 2.03451e-005,62.3881L 2.03451e-005,691.729C 2.03451e-005,726.52 28.1813,754.667 62.9387,754.667L 566.448,
                                              754.667C 601.209,754.667 629.389,726.52 629.389,691.729L 629.389,62.3881C 629.389,27.6 601.209,-0.550598 566.448,
                                              -0.550598 Z ">
            </Path>
            <Border Grid.Column="1" Grid.Row="0">
                <TextBlock x:Name="tbRecNo" VerticalAlignment="Center" Text="RN120700001"/>
            </Border>
            <Border Grid.Column="2" Grid.Row="0">
                <TextBlock x:Name="tbOrderDate" VerticalAlignment="Center" Text="07-08" Foreground="DarkGreen"/>
            </Border>
            <StackPanel Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Orientation="Horizontal">
                <Button x:Name="btnDelete" Style="{StaticResource btnUnfinished}" Tag="/UUCManage.UUCClient;component/Images/DocDelete.png" Background="#00FFFFFF" />
                <Button x:Name="btnTakeOut" Style="{StaticResource btnUnfinished}" Tag="/UUCManage.UUCClient;component/Images/DocTakeOut.png" Background="#00FFFFFF" />
            </StackPanel>
        </Grid>
    </UserControl>

    2012年7月18日 2:10

答案

  • 请看下这个代码是否可以解决你的问题 。

                uc1.Focus();
                this.uc1.GotFocus += (s, o) =>
                {
                    this.uc1.Background = Brushes.Red;
                };


    Kee Poppy [MSFT]
    MSDN Community Support | Feedback to us

    2012年7月18日 9:18
    版主