使用 Jetpack 主题的 Silverlight Datagrid 在编辑内容时不会拉伸文本框
我在一个使用 Datagrids 的应用程序中使用 Jetpack 主题。使用 DataGridTextColumn 编辑绑定内容时,文本框不会一直横向和向下拉伸。当向我的模型添加新项目时,这是一个问题,因为文本的值将为空,文本框的点击区域很小,并且给我们的用户带来了问题。
如何覆盖文本框样式,以便文本框在数据网格的单元格内完全水平和垂直拉伸?对于 DataGridTemplateColumn 内的组合框,我也有同样的问题。当没有默认值时,组合框很小,直到选择一个值为止,一旦选择了一个值,组合框只会拉伸到所选内容的宽度,而不是在网格内填充自身。
我创建了一个没有主题的新项目,一切正常,所以它与 Jetpack 主题有关,但我就是不知道在哪里。有人有什么想法吗?
更新:我尝试使用此样式作为列的 EditElementStyle:
<Style TargetType="TextBox" x:Key="StretchTextBox">
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
这也不起作用。
I'm using the Jetpack theme in an application that some use of Datagrids. When editing the bound content using a DataGridTextColumn, the textbox does not stretch all the way across and down. This is a problem when adding new items to my model, since the value of the text would be null, the textbox's click area is tiny, and is causing problems for our users.
How do I go about overriding the textbox style so the textbox stretches completely, horizontally and vertically, inside the cell of the datagrid? I have the same problem for comboboxes that are inside a DataGridTemplateColumn. When there is no default value, the combobox is tiny until a value is selected, and once a value is selected, the combobox only stretches to the width of the content selected, instead of filling itself inside the grid.
I created a new project using no theming, and everything worked correctly, so it has to do with the Jetpack theme, but I just can't figure out where. Anyone have any ideas?
UPDATE: I tried using this style as the EditElementStyle of the column:
<Style TargetType="TextBox" x:Key="StretchTextBox">
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>
This did not work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
找到
DataGridTemplateColumn
模板/样式TargetType="data:DataGridCell"
找到
ContentPresenter
元素并设置HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
和
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
或者您可能必须更改
ContentTemplate
我没有 Jetpack 主题,但我希望这会有所帮助。我只是猜测可能出了什么问题。
Find the
DataGridTemplateColumn
template/styleTargetType="data:DataGridCell"
Find the
ContentPresenter
element and set theHorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
and
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
or maybe you have to change the
ContentTemplate
I don't have the Jetpack theme, but I hope this helps. I am just guessing what could be wrong.
我已经找到了答案,但我将朗普林的答案标记为已接受,因为他告诉我该怎么做。如果您查看 http://www.silverlight.net/content/samples /sl4/themes/jetpack.html 那里的数据网格做了同样的事情。启动一个没有主题的新 SL 应用程序可以使数据网格按预期工作。注释掉整个 ContentTemplate 会使单元格中的内容按应有的方式填充:
我对主题和动画了解不多,但这似乎可以解决问题。我在活动行周围有一条蓝线,但它并不重要。
I have figured out the answer, but I'm marking Rumplin's answer as accepted because he clued me on what to do. If you look at http://www.silverlight.net/content/samples/sl4/themes/jetpack.html the datagrid there does the same thing. Starting a new SL app with no theme makes the datagrid work as expected. Commenting out the whole ContentTemplate makes the content in the cells fill up as it should be:
I do not know much about theming and animations, but that seemed to do the trick. I have a blue line surrounding the active row but it's insignificant.
JetPack 主题中的 DataGrid 模板存在此问题(单元格内容不拉伸),而 SDK 中的默认模板则没有。上面的答案并没有解决 JetPack 模板的问题;相反,它展示了如何使用默认的 SDK 模板而不是 JetPack 模板。我想我应该发布 JetPack 模板本身的修复程序。
在 JetPack 主题的 SDKStyles.xaml 资源字典中:
默认 SDK 模板与 JetPack 模板之间存在差异的原因是 SDK 使用 ContentPresenter,而 JetPack 模板使用 ContentControl。
The DataGrid template in the JetPack theme has this problem (cell contents not stretching) and the default template in the SDK does not. The answer above doesn't address the problem of the JetPack template; rather it shows how to use the default SDK template instead of the JetPack template. I thought I would post the fix for the JetPack template itself.
In the JetPack theme's SDKStyles.xaml resource dictionary:
The reason for the difference between the default SDK template and the JetPack template is that the SDK uses a ContentPresenter while the JetPack template uses a ContentControl.