开发者

How to change datatemplate through code

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" >
 开发者_JAVA百科       <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>


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;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜