- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试为列表框动态创建数据模板。这是针对自定义用户控件的。此 UserControl 有一个 DependencyProperty,它接受任何类型的 IEnumerable<>。
这工作正常......但输出总是
如果对象包含 2 个属性。但我希望这些属性并排排列。喜欢:
对象 1:
对象 2:
那么我哪里错了?我首先制作一个 Stackpanel,然后在 Stackpanel 中制作包含标签的 Dockpanel。
这是它目前的一个小预览。
所以这是我创建数据模板的代码:
DataTemplate _NewData = new DataTemplate();
FrameworkElementFactory _template = new FrameworkElementFactory(typeof(StackPanel));
foreach (var _FProperty in view.CurrentItem.GetType().GetProperties())
{
FrameworkElementFactory _firstTemplateChild = new FrameworkElementFactory(typeof(DockPanel));
FrameworkElementFactory _childOneForDock = new FrameworkElementFactory(typeof(Label));
_childOneForDock.SetValue(Label.ContentProperty, _FProperty.Name);
_firstTemplateChild.AppendChild(_childOneForDock);
FrameworkElementFactory _childTwoForChild = new FrameworkElementFactory(typeof(Label));
_childTwoForChild.SetBinding(Label.ContentProperty, new Binding(_FProperty.Name));
_firstTemplateChild.AppendChild(_childTwoForChild);
_template.AppendChild(_firstTemplateChild);
}
_NewData.VisualTree = _template;
ListBoxInPopUp.ItemTemplate = _NewData;
最佳答案
StackPanel
的默认方向是垂直的。
您需要将方向设置为水平以使内容并排显示。
在 MSDN 中的代码示例中它指出:
<!-- The items under this StackPanel are stacked Vertically. Note that Orientation
has a default value of "Vertical" but in this example the property is explicitely
set for clarity. -->
(拼写错误都是他们的)
DockPanel.Dock
属性的默认值也是 Left,但我不确定在这种情况下这是否是一个因素。
关于C# WPF 在 Stackpanel 中以编程方式创建的 DataTemplate Dockpanel 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4788137/
我有一个包含子 StackPanel 的 StackPanel(在后面的代码中添加)。 父堆栈面板 子堆栈面板 for (int i=1;i 如果您仅将 StackP
假设我们有一个水平方向且宽度为 100 像素的 Stackpanel。 在里面我制作了 11 个宽度为 10px 的方形 Canvas 绘图。 这意味着最后一个正方形将在 View 之外,因为它将扩展
我有两个停靠面板,每个停靠面板都有一个左侧 StackPanel。 的宽度底部 StackPanel 由 的宽度决定文字 在里面。 的宽度顶部 StackPanel 应该是 相同作为 的宽度底部 堆栈
我正在尝试创建一个 DataTamplate,它应该包含一个具有一定数量 StackPanel 的 StackPanel。
我有以下 WPF 控件 应用程序运行时看起来像这样。 问题是 - 当我的鼠标位于按钮之间时,弹出窗口已关闭。 (U、B、NB键之间的空隙) 如您所见 - Popup.IsOpen 属性绑定(bind)
有没有办法在运行时更改 StackPanel 内控件的顺序? 非常感谢, 保罗 最佳答案 stackPanel1.Children.Remove(item); stackPanel1.Children
我想在 ListBoxItem 上放一个命令。 ListBoxItem 使用由 StackPanel(包含 Image 和 TextBlock,均使用 Binding)组成的 DataTemplate
我有一个 Stackpanel 并希望项目根据其内容自动设置其大小,但项目不应自动填充 Stackpanel 的高度(但 Stackpanel 应根据最大项目具有自动高度)。我也试过 WrapPane
在这样的场景中: 是否可以拉伸(stretch)控制列表中的最后一个元素 (Element2) 以适应所有可能的空间(如 width="*")? 我被迫使用网格? 最佳答案
我对 WPF 很陌生,所以如果我遗漏了一些明显的东西,我深表歉意。我有这个模板绑定(bind)到 obs 中的项目。收藏。我试图让第二列,“测试测试......”部分具有可变宽度,填充父网格中的所有可
XAML有办法吗?说我想垂直居中对齐水平方向内的所有组件 StackPanel ? 我用下面的 XAML 达到了预期的结果: 但我需要重
对于 WPF/Silverlight 布局,使用具有大量行和列的 Grid 还是大量 Stackpanels 更好? 最佳答案 如果您需要水平和垂直排列的东西,您应该使用网格。当这些东西不需要与其他任
我试图在单击按钮时显示一个折叠的堆栈面板,但我遇到了问题,所以我尝试扭转我的想法,我能够折叠一个可见的堆栈面板。但不幸的是,我无法实现我想要的行为,在按钮单击时显示折叠的堆栈面板。到代码:D XAML
我需要用 stackpanel (框架)中的最后一个元素填充空白空间: _mainFrame
我是 WPF 的新手,我无法弄清楚一些事情。我刚开始一个新项目,我想制作一个 StackPanel,因为我在教程中看到了它。但是现在我已经实现了 StackPanel 并且出现了 2 个错误。 The
我正在尝试设置 StackPanel 的填充,但没有这样的属性。我尝试了 StackPanel.Border,但也没有这样的属性。 有什么想法吗? 最佳答案 您可以在 StackPanel 周围放置一
我正在尝试创建一个具有圆形背景的堆栈面板,它还有一个从灰色到透明的线性画笔 我用这里暴露的思路来防止裁剪 http://chriscavanagh.wordpress.com/2008/10/03/w
我是 WPF 的新手,我无法弄清楚一些事情。我刚开始一个新项目,我想制作一个 StackPanel,因为我在教程中看到了它。但是现在我已经实现了 StackPanel 并且出现了 2 个错误。 The
我试图在堆栈面板中插入多个矩形,但我不断收到错误消息“元素已经是另一个元素的子元素。”。如果我使用 Canvas ,也会发生同样的事情。 例子: List recList = new List();
我对 WPF 很陌生。我有一个使用 L2S 显示来自 SQL 数据库的数据的页面。 L2S 返回一个 DataTable,其中包含可供特定区域选择的所有可用选项。它从数据库返回的每一行都需要是一个 c
我是一名优秀的程序员,十分优秀!