XAML:我能得到“吗?”;“下一个控件”;在堆叠的面板中,并将其绑定';谁的财产?

XAML:我能得到“吗?”;“下一个控件”;在堆叠的面板中,并将其绑定';谁的财产?,xaml,binding,styles,Xaml,Binding,Styles,我想做的是,如果一个多边形旁边的stackedpanel中的文本框有焦点,那么它就可以显示。基本上,它将是一个指示文本框有焦点的指示器。这将应用于多个文本框,因此我希望使用样式使其通用 <StackPanel Visibility="{Binding showOpCode}" Margin="0,2" Orientation="Horizontal" > <TextBlock Width="212" VerticalAlignment="Center"&

我想做的是,如果一个多边形旁边的stackedpanel中的文本框有焦点,那么它就可以显示。基本上,它将是一个指示文本框有焦点的指示器。这将应用于多个文本框,因此我希望使用样式使其通用

<StackPanel Visibility="{Binding showOpCode}" Margin="0,2" Orientation="Horizontal" >
            <TextBlock Width="212" VerticalAlignment="Center">Operation Code:</TextBlock>
            <Polygon Width="29" Points="14,8 14,21 28,14.5" Fill="Gray" Stroke="DarkGray"/>
            <TextBox HorizontalContentAlignment="Right" 
                     Name="txtOpCode" VerticalAlignment="Bottom" Width="122" Text="0"
                     Style="{StaticResource normalTextBoxStyle}" />
        </StackPanel>

操作代码:

您最好构建一个包含多边形的自定义文本框样式。可以从中获取默认样式

只需使用文本框和相关资源的默认样式,然后将多边形添加到左侧

比如:

<LinearGradientBrush x:Key="TextBoxBorder"
                     StartPoint="0,0"
                     EndPoint="0,20"
                     MappingMode="Absolute">
    <LinearGradientBrush.GradientStops>
        <GradientStop Color="#ABADB3"
                      Offset="0.05"/>
        <GradientStop Color="#E2E3EA"
                      Offset="0.07"/>
        <GradientStop Color="#E3E9EF"
                      Offset="1"/>
    </LinearGradientBrush.GradientStops>
</LinearGradientBrush>

<Style x:Key="CustomTextBoxStyle" TargetType="{x:Type TextBox}">
    <Setter Property="Foreground"
            Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Background"
            Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
    <Setter Property="BorderBrush"
            Value="{StaticResource TextBoxBorder}"/>
    <Setter Property="BorderThickness"
            Value="1"/>
    <Setter Property="Padding"
            Value="1"/>
    <Setter Property="AllowDrop"
            Value="true"/>
    <Setter Property="FocusVisualStyle"
            Value="{x:Null}"/>
    <Setter Property="ScrollViewer.PanningMode"
            Value="VerticalFirst"/>
    <Setter Property="Stylus.IsFlicksEnabled"
            Value="False"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBoxBase}">
                <DockPanel>
                    <Polygon x:Name="polygon" DockPanel.Dock="Left" Width="29" Points="14,8 14,21 28,14.5" Fill="Gray" Stroke="DarkGray"/>
                    <theme:ListBoxChrome x:Name="Bd"
                                          BorderThickness="{TemplateBinding BorderThickness}"
                                          BorderBrush="{TemplateBinding BorderBrush}"
                                          Background="{TemplateBinding Background}"
                                          RenderMouseOver="{TemplateBinding IsMouseOver}"
                                          RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"
                                          SnapsToDevicePixels="true">
                        <ScrollViewer x:Name="PART_ContentHost"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </theme:ListBoxChrome>
                </DockPanel>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled"
                             Value="false">
                        <Setter TargetName="Bd"
                                Property="Background"
                                Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                        <Setter Property="Foreground"
                                Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                    <Trigger Property="IsKeyboardFocusWithin"
                             Value="false">
                        <Setter TargetName="polygon"
                                Property="Visibility"
                                Value="Collapsed"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


其中xmlns
主题
定义为
xmlns:theme=“clr namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero”
。您需要向PresentationFramework.Aero.dll添加一个ref,或者将其从ListBoxChrome更改为边框。

您最好构建一个包含多边形的自定义文本框样式。可以从中获取默认样式

只需使用文本框和相关资源的默认样式,然后将多边形添加到左侧

比如:

<LinearGradientBrush x:Key="TextBoxBorder"
                     StartPoint="0,0"
                     EndPoint="0,20"
                     MappingMode="Absolute">
    <LinearGradientBrush.GradientStops>
        <GradientStop Color="#ABADB3"
                      Offset="0.05"/>
        <GradientStop Color="#E2E3EA"
                      Offset="0.07"/>
        <GradientStop Color="#E3E9EF"
                      Offset="1"/>
    </LinearGradientBrush.GradientStops>
</LinearGradientBrush>

<Style x:Key="CustomTextBoxStyle" TargetType="{x:Type TextBox}">
    <Setter Property="Foreground"
            Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Background"
            Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
    <Setter Property="BorderBrush"
            Value="{StaticResource TextBoxBorder}"/>
    <Setter Property="BorderThickness"
            Value="1"/>
    <Setter Property="Padding"
            Value="1"/>
    <Setter Property="AllowDrop"
            Value="true"/>
    <Setter Property="FocusVisualStyle"
            Value="{x:Null}"/>
    <Setter Property="ScrollViewer.PanningMode"
            Value="VerticalFirst"/>
    <Setter Property="Stylus.IsFlicksEnabled"
            Value="False"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TextBoxBase}">
                <DockPanel>
                    <Polygon x:Name="polygon" DockPanel.Dock="Left" Width="29" Points="14,8 14,21 28,14.5" Fill="Gray" Stroke="DarkGray"/>
                    <theme:ListBoxChrome x:Name="Bd"
                                          BorderThickness="{TemplateBinding BorderThickness}"
                                          BorderBrush="{TemplateBinding BorderBrush}"
                                          Background="{TemplateBinding Background}"
                                          RenderMouseOver="{TemplateBinding IsMouseOver}"
                                          RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"
                                          SnapsToDevicePixels="true">
                        <ScrollViewer x:Name="PART_ContentHost"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </theme:ListBoxChrome>
                </DockPanel>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled"
                             Value="false">
                        <Setter TargetName="Bd"
                                Property="Background"
                                Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                        <Setter Property="Foreground"
                                Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                    <Trigger Property="IsKeyboardFocusWithin"
                             Value="false">
                        <Setter TargetName="polygon"
                                Property="Visibility"
                                Value="Collapsed"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


其中xmlns
主题
定义为
xmlns:theme=“clr namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero”
。你需要在PresentationFramework.Aero.dll中添加一个ref,或者将其从ListBoxChrome更改为Border。

Dude,你根本无法解决这个问题。我明天会调查的。多谢了,老兄,你根本没法回答这个问题。我明天会调查的。非常感谢。