为什么以下代码不起作用? - xaml中的空指针异常

时间:2011-12-31 02:06:14

标签: wpf xaml triggers focus setter

我在setter中的targetname上得到一个空指针异常,我在其中设置focusmanager.focuselement属性。我不确定为什么它不起作用。任何帮助将不胜感激。

 <Style x:Key="DesignerItemStyle" TargetType="ContentControl">
        <Setter Property="MinHeight" Value="50"/>
        <Setter Property="MinWidth" Value="50"/>
        <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ContentControl">
                    <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                        <s:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/> 
                        <Control x:Name="ResizeDecorator" Template="{StaticResource ResizeDecoratorTemplate}" Visibility="Collapsed"/>
                        <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
                        <TextBox x:Name="textboxName" Text="node" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" Height="Auto" IsHitTestVisible="False"/>
                        <TextBox x:Name="count" Text="100" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="Auto" Height="Auto" IsHitTestVisible="False"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsKeyboardFocused" Value="True">
                            <Setter TargetName="ResizeDecorator" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsManipulationEnabled" Value="True">
                            <Setter TargetName="textboxName" Property="IsHitTestVisible" Value="True"/>
                            <Setter TargetName="textboxName" Property="FocusManager.FocusedElement" Value="textboxName"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

1 个答案:

答案 0 :(得分:0)

我的代码中没有看到targetname。开始删除样式的片段,直到它编译以缩小问题范围。