使用 Jetpack 主题的 Silverlight Datagrid 在编辑内容时不会拉伸文本框

发布于 2024-12-06 17:36:33 字数 600 浏览 0 评论 0原文

我在一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

段念尘 2024-12-13 17:36:33

找到 DataGridTemplateColumn 模板/样式 TargetType="data:DataGridCell"

<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>

找到 ContentPresenter 元素并设置
Horizo​​ntalAlignment="{TemplateBinding Horizo​​ntalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"

或者您可能必须更改 ContentTemplate

我没有 Jetpack 主题,但我希望这会有所帮助。我只是猜测可能出了什么问题。

Find the DataGridTemplateColumn template/style TargetType="data:DataGridCell"

<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>

Find the ContentPresenter element and set the
HorizontalAlignment="{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.

无声情话 2024-12-13 17:36:33

我已经找到了答案,但我将朗普林的答案标记为已接受,因为他告诉我该怎么做。如果您查看 http://www.silverlight.net/content/samples /sl4/themes/jetpack.html 那里的数据网格做了同样的事情。启动一个没有主题的新 SL 应用程序可以使数据网格按预期工作。注释掉整个 ContentTemplate 会使单元格中的内容按应有的方式填充:

<Style TargetType="sdk:DataGridCell">
    <Setter Property="FontFamily" Value="{StaticResource NormalFontFamily}" />
    <Setter Property="FontSize" Value="{StaticResource DefaultFontSize}" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="HorizontalAlignment" Value="Stretch" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Padding" Value="7"/>
    <!--
    <Setter Property="Template" Value="{StaticResource DataGridCellTemplate}" />
-->
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>

我对主题和动画了解不多,但这似乎可以解决问题。我在活动行周围有一条蓝线,但它并不重要。

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:

<Style TargetType="sdk:DataGridCell">
    <Setter Property="FontFamily" Value="{StaticResource NormalFontFamily}" />
    <Setter Property="FontSize" Value="{StaticResource DefaultFontSize}" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="HorizontalAlignment" Value="Stretch" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="Padding" Value="7"/>
    <!--
    <Setter Property="Template" Value="{StaticResource DataGridCellTemplate}" />
-->
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>

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.

烟织青萝梦 2024-12-13 17:36:33

JetPack 主题中的 DataGrid 模板存在此问题(单元格内容不拉伸),而 SDK 中的默认模板则没有。上面的答案并没有解决 JetPack 模板的问题;相反,它展示了如何使用默认的 SDK 模板而不是 JetPack 模板。我想我应该发布 JetPack 模板本身的修复程序。

在 JetPack 主题的 SDKStyles.xaml 资源字典中:

  1. 使用 x:Key="DataGridCellTemplate" 找到 ControlTemplate 元素
  2. 在 ControlTemplate 中,找到 ContentControl 元素
  3. 将 Horizo​​ntalContentAlignment 和 VerticalContentAlignment 设置为在 ContentControl 上拉伸。

默认 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:

  1. Locate the ControlTemplate element with x:Key="DataGridCellTemplate"
  2. In the ControlTemplate, locate the ContentControl element
  3. Set HorizontalContentAlignment and VerticalContentAlignment to Stretch on the ContentControl.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文