C# 访问和修改数据模板中网格行的属性
尽管定义了网格或行的名称,我还是很难访问网格或其行(在列表框中)。当某个参数从SharePoint browsable属性传递到Silverlight控件时,我打算将新的MaxHeight设置为其中一行 我怎样才能达到预期的效果?也许吧 @Page.xaml:C# 访问和修改数据模板中网格行的属性,c#,xaml,silverlight-2.0,C#,Xaml,Silverlight 2.0,尽管定义了网格或行的名称,我还是很难访问网格或其行(在列表框中)。当某个参数从SharePoint browsable属性传递到Silverlight控件时,我打算将新的MaxHeight设置为其中一行 我怎样才能达到预期的效果?也许吧 @Page.xaml: <ListBox ItemsSource="{Binding}" DataContext="" x:Name="NewsList" SelectionChanged="NewsList_SelectionChanged" Se
<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>
我相信StaffNews代表了你名单上的一个项目,对吗 在这种情况下,要为特性指定值,请使用:
test.StaffNewsBodyHeight = 200;
替换代码段的最后一行
[p.S.-StaffNewsBodyHeight是StaffNews中定义的一个依赖属性,对吗?]非常感谢。顺便说一句,找到了一个有效的解决方法。非常感谢!:)
test.StaffNewsBodyHeight = 200;