访问和修改数据模板中网格行的属性



尽管定义了网格或行名,我还是很难访问一个网格或它的行(在ListBox内)。当一些参数从SharePoint可浏览属性传递到Silverlight控件时,我打算设置一个新的MaxHeight为它的一行。

我怎样才能达到预期的效果?也许绑定?

@ Page.xaml:

   <ListBox ItemsSource="{Binding}" DataContext="" x:Name="NewsList" SelectionChanged="NewsList_SelectionChanged" SelectionMode="Single" Width="580" Height="360" VerticalAlignment="Top" HorizontalAlignment="Center" >
                                    <ListBox.ItemTemplate>
                                        <DataTemplate >                                       
                                                                                                <Grid Height="110" Width="540" x:Name="StaffNewsBodyHeight">
                                                     <Grid Height="110" Width="540">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="15" />
                                                    <RowDefinition Height="{Binding StaffNewsBodyHeight}" />
                                                    <RowDefinition Height="15" />
                                                </Grid.RowDefinitions>                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="82"  />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>                                            
                                                    <Border CornerRadius="2" BorderThickness="2" BorderBrush="Gray" Height="82" Width="82" Background="LemonChiffon" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.RowSpan="3" Grid.Column="0" >                                                
                                                        <Image Source="{Binding NewsThumbnail}" Style="{StaticResource ThumbNailPreview}" />
                                                    </Border>
                                                    <TextBlock x:Name="NewsTitle" FontFamily="Arial" FontWeight="bold"  TextDecorations="Underline" Text="{Binding Title}"  Style="{StaticResource TitleText}" Grid.Row="0" Grid.Column="1"/>                                         
                          <TextBlock x:Name="NewsBody" FontFamily="Arial" Text="{Binding NewsBody}" Margin="5" Style="{StaticResource DescriptionBlock}" Grid.Row="1" Grid.Column="1" />

                                                    <StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1" Margin="3,3,3,3">
                                                        <TextBlock Text="Published By:" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" /> 
                                                        <TextBlock Text="{Binding PublishedBy}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" />
                                                        <TextBlock Text="{Binding DatePublished}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Foreground="Gray" FontWeight="Bold" FontSize="9" />                                                    
                                                    </StackPanel>                                                
                                                </Grid>                                       
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>

@ Page.xaml.cs:

if (!string.IsNullOrEmpty(_setLength))
        {               
            StaffNews test = new StaffNews();
            //assign new height to gridrow of NewsBody
            if (_setLength.Contains("_3"))
                test.StaffNewsBodyHeight.Equals(200);
        }

我相信StaffNews代表列表中的一个项目,对吗?

在这种情况下,要给属性赋值,使用:

test.StaffNewsBodyHeight = 200;

替换代码片段的最后一行。

(注:

- StaffNewsBodyHeight是在StaffNews中定义的依赖属性,对吗?)

相关内容

  • 没有找到相关文章