[英]Bind a CodeBehind instance of StackPanel to XAML
I have an odd scenario. 我有一个奇怪的情况。
I need to create a StackPanel in codebehind. 我需要在代码隐藏中创建一个StackPanel。 I then need to have that stackpanel bound to the UI in xaml.
然后,我需要将该堆栈面板绑定到xaml中的UI。
Normally I would just use a ContentControl for this. 通常,我只会为此使用ContentControl。 But it has focus issues (it cannot blocked from the tab order Focusable="False" has no effect).
但是它具有焦点问题(不能从选项卡顺序Focusable =“ False”阻止)。 I also tried a usercontrol, but that had the same issues.
我也尝试了一个usercontrol,但是有同样的问题。
So I need to use some other kind of control. 因此,我需要使用其他某种控件。 I have decided on a Panel.
我决定成立一个小组。 (StackPanel seems as good as any of the panels.)
(StackPanel看起来和其他面板一样好。)
However, I can't seem to find a way to bind to my "In Code" stack panel in my Xaml? 但是,我似乎找不到在Xaml中绑定到“ In Code”堆栈面板的方法吗?
Is there a way to do this? 有没有办法做到这一点? (WITHOUT using a contentcontrol or usercontrol)
(不使用contentcontrol或usercontrol)
it cannot blocked from the tab order Focusable="False" has no effect
它不能从选项卡顺序中阻止Focusable =“ False”无效
What about IsTabStop
? 那么
IsTabStop
呢?
Also the most lightweight thing to use is a ContentPresenter
which is what i would use. 另外,要使用的最轻便的东西是
ContentPresenter
,这就是我要使用的东西。
Tested this in KAXAML, and the focus doesn't go to any of the items defined in the ContentPresenter or ContentControl when TAB is pressed. 在KAXAML中进行了测试,按下TAB时,焦点不会移至ContentPresenter或ContentControl中定义的任何项目。
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<TextBox>aaaaa</TextBox>
<TextBox>bbbbb</TextBox>
<ContentControl Focusable="False">
<ContentControl.ContentTemplate>
<DataTemplate>
<StackPanel Focusable="False" Background="Red" Width="100" Height="50"></StackPanel>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
<ContentControl Focusable="False">
<ContentControl.ContentTemplate>
<DataTemplate>
<TextBox Focusable="False">hello</TextBox>
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
<ContentPresenter Focusable="False">
<ContentPresenter.Content>
<TextBox Focusable="False">hello</TextBox>
</ContentPresenter.Content>
</ContentPresenter>
<TextBox>ccccc</TextBox>
<TextBox>ddddd</TextBox>
</StackPanel>
</Page>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.