2014-01-24 39 views
2

我對XAML和WPF相當陌生但是我正在嘗試以下操作。IsExpanded綁定

我使用基於groupDescription的擴展器構建ListView。哪些工作正常。 現在我試圖將IsExpanded屬性綁定到一個項目,因爲如果我切換了我的應用程序中的選項卡,則先前用戶對擴展和摺疊擴展器的選擇將被刪除。這意味着所有的擴展器都會被拖回崩潰狀態,這非常煩人。

但是我真的不明白這應該如何工作。我可以將擴展器的IsExpanded屬性綁定到我的相應類中的屬性嗎?如何區分不同的羣體?

非常感謝你

<ListView Name="Mails" local:FM.Register="{Binding}" local:FM.GetFocus="Loaded" 
        Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
        ItemsSource="{Binding Path=MailsProxy.View}" 
        SelectionMode="Single" SelectedItem="{Binding Path=SelectedMail, Mode=TwoWay}" 
        local:SortList.BringIntoViewSelected="True" local:SortList.IsGridSortable="True" 
        ItemContainerStyle="{StaticResource InboxMailItem}" 
        View="{Binding Source={x:Static session:Session.Current}, Path=InboxView.View}"> 
      <ListView.GroupStyle> 
       <GroupStyle> 
        <GroupStyle.ContainerStyle> 
         <Style TargetType="{x:Type GroupItem}"> 
          <Setter Property="Margin" Value="0,0,0,5"/> 
          <Setter Property="Template"> 
           <Setter.Value> 
            <ControlTemplate TargetType="{x:Type GroupItem}"> 
             <Expander Foreground="Black" BorderThickness="0,0,0,1" Style="{StaticResource ExpanderStyle}"> 
              <Expander.Header> 
               <DockPanel> 
                <TextBlock FontWeight="Bold" FontSize="14" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}, Path=DataContext.GroupBy}"/> 
                <TextBlock FontWeight="Bold" FontSize="14">:</TextBlock> 
                <TextBlock FontSize="14" Text="{Binding Path=Name, Converter={StaticResource GroupHeaderConverter}}" Margin="5,0,0,0"/> 
               </DockPanel> 
              </Expander.Header> 
               <ItemsPresenter /> 
             </Expander> 
            </ControlTemplate> 
           </Setter.Value> 
          </Setter> 
         </Style> 
        </GroupStyle.ContainerStyle> 
       </GroupStyle> 
      </ListView.GroupStyle> 
      <ListView.Resources> 
       <Style TargetType="{x:Type GridViewColumnHeader}"> 
        <Setter Property="DataContext" Value="{Binding Source={x:Static session:Session.Current}, Path=InboxView}"/> 
       </Style> 
      </ListView.Resources> 
     </ListView> 

回答

-1

定義一些靜態布爾變量,設置屬性爲他們當用戶展開或摺疊特定的節點,然後分配相應的值布爾變量即isExpanded = Mails.Expanded和當u在頁面渲染或頁面加載時再次回到同一個選項卡,檢查靜態變量的值並將相同的值分配給Mails.Expanded = isExpanded這將解決您的問題

+0

感謝您的回覆,您可以詳細瞭解一下嗎? – Xeun

-1

代碼會是這樣的。

static bool isExpanded = false; 

我正在考慮窗口1是到其中的列表視圖控件添加

private void Window1_Load(object sender, RoutedEventArgs e) 
{ 
    Mails.Expanded = isExpanded; 
    //... rest of your code 
} 

private void Mails_SelectionChanged(object sender, RoutedEventArgs e) 
{ 
    isExpaned = Mails.Expanded; 
} 

希望這會清除您的視圖窗口的名稱。

+0

如果我沒有弄錯,這隻會觸發所有組被摺疊或展開,而不是由GroupDescription生成的特定組,或者我誤會了嗎? – Xeun

+0

是的,我可能是錯的,但我只是建議你的解決方案,你可以爲每個組制定一個擴展標誌的靜態列表,並在Window_load中,你可以檢索這些值,並將它們分配給每個組的擴展屬性..希望這可以解決你的問題如果需要進一步的幫助,請求它 –

+0

我對你很誠實我不知道你想如何實現這個... – Xeun