2011-07-29 42 views
0

內我很難獲得網格或它的行(一個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); 
     } 

回答

0

我相信StaffNews是代表你的列表中的一個項目,對不對?

在這種情況下,分配一個值的屬性,使用方法:

test.StaffNewsBodyHeight = 200; 

,以取代片段的最後一行。

[P.S. - StaffNewsBodyHeight是StaffNews定義的依賴屬性,右]

+0

非常感謝順便說一句?找到了解決方法。非常感激! :) – brainsfrying