XAML:我可以获得“下一个控件”吗?在堆叠面板中并绑定到它的属性?
我想要做的是,如果旁边的 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>
What I'm looking to do is make a polygon visible if the textbox in the stackedpanel next to it has focus. Basically, it'll be an indicator to which textbox has focus. This is going to be applied to multiple textboxes so I'd like to make it generic, using a style.
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您最好构建一个包含多边形的自定义文本框样式。您可以从此处。
只需采用 TextBox 和相关资源的默认样式,然后将多边形添加到左侧即可。
类似于:
其中 xmlns
theme
定义为xmlns:theme="clr-namespace:Microsoft.Windows.Themes; assembly=PresentationFramework.Aero"
。您需要添加对PresentationFramework.Aero.dll 的引用,或将其从ListBoxChrome 更改为Border。You would be better off building a custom TextBox style that includes the Polygon. You can get the default Styles from here.
Just take the default Style for TextBox and related resources, then add your polygon to the left.
Something like:
Where the xmlns
theme
is defined asxmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
. You'd need to add a ref to PresentationFramework.Aero.dll, or change it from a ListBoxChrome to a Border.