如何通过代码更改数据模板

发布于 2024-09-28 15:01:24 字数 1014 浏览 4 评论 0原文

我有 ListBox 和 DataTemplate

我需要 Set GroupBox Heigth = 300

如何做到这一点?

<DataTemplate x:Key="data_template">
    <GroupBox Header="Категория" Width="300"  HorizontalAlignment="Stretch" x:Name="GroupBox">
    <DockPanel Tag="{Binding id}">
        <Button Click="Button_Click" DockPanel.Dock="Top" >
        <Button.Content>
            <DockPanel>
            <TextBlock Text="{Binding title}" TextWrapping="Wrap" DockPanel.Dock="Top" Padding="5"  HorizontalAlignment="Center"  Foreground="#FFB51414" />
            <l:ScrollViewerEx  VerticalScrollBarVisibility="Auto" >
                <TextBlock Text="{Binding description}" DockPanel.Dock="Top" TextWrapping="Wrap" Padding="5" IsHitTestVisible="False" />
            </l:ScrollViewerEx>
            </DockPanel>
        </Button.Content>
        </Button>
    </DockPanel>
    </GroupBox>
</DataTemplate>

I have ListBox and DataTemplate

I need Set GroupBox Heigth = 300

How to do it?

<DataTemplate x:Key="data_template">
    <GroupBox Header="Категория" Width="300"  HorizontalAlignment="Stretch" x:Name="GroupBox">
    <DockPanel Tag="{Binding id}">
        <Button Click="Button_Click" DockPanel.Dock="Top" >
        <Button.Content>
            <DockPanel>
            <TextBlock Text="{Binding title}" TextWrapping="Wrap" DockPanel.Dock="Top" Padding="5"  HorizontalAlignment="Center"  Foreground="#FFB51414" />
            <l:ScrollViewerEx  VerticalScrollBarVisibility="Auto" >
                <TextBlock Text="{Binding description}" DockPanel.Dock="Top" TextWrapping="Wrap" Padding="5" IsHitTestVisible="False" />
            </l:ScrollViewerEx>
            </DockPanel>
        </Button.Content>
        </Button>
    </DockPanel>
    </GroupBox>
</DataTemplate>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

小镇女孩 2024-10-05 15:01:24

如果有人试图解决我之前的问题,我会这样做:

DataTemplate mycolumnDataTemplate = null;
var dataTemplateStream = new SomeClass().GetType().Assembly.GetManifestResourceStream("Some.Namespace.SomeReosurceName.xaml");
string dataTemplateString = new System.IO.StreamReader(dataTemplateStream).ReadToEnd();
dataTemplateString = dataTemplateString.Replace("[0]", browserColumn.ColumnName);
mycolumnDataTemplate = XamlReader.Load(dataTemplateString) as DataTemplate;

In case, someone tried to resolve my previous question, I did it like the following:

DataTemplate mycolumnDataTemplate = null;
var dataTemplateStream = new SomeClass().GetType().Assembly.GetManifestResourceStream("Some.Namespace.SomeReosurceName.xaml");
string dataTemplateString = new System.IO.StreamReader(dataTemplateStream).ReadToEnd();
dataTemplateString = dataTemplateString.Replace("[0]", browserColumn.ColumnName);
mycolumnDataTemplate = XamlReader.Load(dataTemplateString) as DataTemplate;
ま昔日黯然 2024-10-05 15:01:24

你想达到什么目的?当某些事件发生或某些数据发生更改时,您是否希望在应用程序运行时更改 GroupBox 高度?如果是这样,那么您可能正在寻找的是数据触发器或事件触发器,您只需将其添加到 DataTemplate 中即可。

What are you trying to achieve? Do you want the GroupBox Height to be changed at the runtime of your application, when some event occurred or some data has changed? If so, then what you are probably looking for is a data trigger or event trigger, which you simply need to add to your DataTemplate.

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