Доступ и изменение свойств строки сетки в шаблоне данных - PullRequest
0 голосов
/ 29 июля 2011

Мне трудно получить доступ к сетке или ее строкам (в ListBox), несмотря на определение имени сетки или строки. Я намерен установить новый MaxHeight для одной из его строк, когда какой-либо параметр передается из свойства просмотра SharePoint в элемент управления Silverlight.

Как мне достичь желаемого эффекта? Связывание возможно?

@ 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);
        }

1 Ответ

0 голосов
/ 30 июля 2011

Я считаю, что StaffNews представляет один элемент в вашем списке, верно?

В этом случае, чтобы присвоить значение свойству, используйте:

test.StaffNewsBodyHeight = 200;

для замены последнегострока вашего фрагмента.

[PS - StaffNewsBodyHeight является свойством зависимости , определенным в StaffNews, верно?]

...