HOW TO CHANGE DATATEMPLATE THROUGH CODE

lois waisbrooker

Total Post:70

Points:494
Posted by  lois waisbrooker
WPF 
WPF
 1192  View(s)
Ratings:
Rate this:
Hi!

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>

Thanks in Advance

  1. shreesh chandra shukla

    Post:105

    Points:735
    Re: How to change datatemplate through code

    Hi!

    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;

    thanks


Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!