开发者

i want to change datatemplete which is in listbox on run time in window phone 7

   <System_Windows_Controls:TabItem  Name="home" Style="开发者_运维百科{StaticResource TabItemStyle1}"  Margin="0,-37,3,0" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Stretch" MouseEnter="mouse_ener" Loaded="Button_Click">
            <ListBox Height="572" HorizontalAlignment="Stretch" Margin="8,6,0,0" Name="listBox1" VerticalAlignment="Stretch"   Background="#00537393" Width="445">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border  BorderBrush="Black" CornerRadius="8" BorderThickness="1" HorizontalAlignment="Stretch" Name="border">
                            <Border.Background>
                                <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                                    <GradientStop Color="#FFB1B7CB" Offset="0" />
                                    <GradientStop Color="#FFC1C8D4" Offset="1" />
                                </LinearGradientBrush>
                            </Border.Background>
                            <Grid Height="106"  HorizontalAlignment="Stretch" Name="grid1" VerticalAlignment="Stretch">

                                <Grid.RowDefinitions>
                                    <RowDefinition Height="0*" />
                                    <RowDefinition Height="100*" />
                                </Grid.RowDefinitions>
                                <Image Height="68" HorizontalAlignment="Left" Margin="13,12,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="92" Grid.Row="1" Source="{Binding ImageSource}" />
                                <TextBlock Foreground="Black" Height="68" HorizontalAlignment="Left" Margin="111,12,0,0" Name="textBlock1" Text="{Binding Title}" VerticalAlignment="Top" Width="280" TextWrapping="Wrap" Grid.Row="1" />
                                <Image Grid.Row="1" Height="75" HorizontalAlignment="Left" Margin="380,12,0,0" Name="image2" Stretch="Fill" VerticalAlignment="Top" Width="73"  Source="/WindowsPhoneApplication7;component/Images/u50.png" />
                                <TextBlock  Foreground="Black" Grid.Row="1" Height="29" HorizontalAlignment="Left" Margin="111,69,0,0" Name="textBlock2" Text="{Binding date}" VerticalAlignment="Top" Width="168" />
                            </Grid>

                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <System_Windows_Controls:TabItem.HeaderTemplate>
                <DataTemplate >
                    <StackPanel>
                        <Image Height="32" Width="32" Source="Images/u28.png"></Image>
                        <TextBlock Text=" Home "></TextBlock>
                    </StackPanel>
                </DataTemplate>
            </System_Windows_Controls:TabItem.HeaderTemplate>
        </System_Windows_Controls:TabItem>


     basically i want to change  textblock hight property  as per orientation landscape and portrait.....


Define your DataTemplate within your UserControl resources, and name your ListBox:

<UserControl>
  <UserControl.Resources>
    <DataTemplate x:Key="myTemplate">
       <!-- new template goes here -->
    </DataTemplate>
  </UserControl.Resources>

  <ListBox x:Name="MyListBox"/>
<UserControl>

Now simply set your ItemTemplate in code-behind when you want to dynamically change it:

MyListBox.ItemTemplate = (DataTemplate)this.Resources["myTemplate"];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜