Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 扩展绑定_C#_Wpf_Expander - Fatal编程技术网

C# 扩展绑定

C# 扩展绑定,c#,wpf,expander,C#,Wpf,Expander,我对XAML和WPF很陌生,但我正在尝试以下内容 我基于groupDescription构建了一个带有扩展器的ListView。这很好用。 现在我正试图将IsExpanded属性绑定到一个项目,因为如果我在应用程序中切换选项卡,以前用户选择的展开和折叠展开器将被删除。这意味着所有的扩展器都会默认返回到崩溃状态,这很烦人 然而,我真的不明白这应该如何工作。我可以将扩展器的IsExpanded属性绑定到相应类中的属性吗?如何区分不同的群体 多谢各位 <ListView Name="Mails"

我对XAML和WPF很陌生,但我正在尝试以下内容

我基于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>

:

定义一些静态布尔变量并为其设置属性,当用户展开或折叠特定节点时,将相应的值分配给布尔变量,即isExpanded=Mail.Expanded,当您在页面呈现或页面加载中再次返回到同一选项卡时,检查静态变量的值并将相同的值分配给Mails.Expanded=isExpanded这将解决您的问题

定义一些静态布尔变量并为它们设置属性,当用户展开或折叠特定节点时,将相应的值分配给布尔变量,即isExpanded=Mails.Expanded,当您在页面呈现或页面加载中再次回到同一选项卡时,请检查静态变量的值,并为邮件分配相同的值。Expanded=isExpanded这将解决您的问题

代码如下所示

static bool isExpanded = false;
我认为Window1是添加列表视图控件的窗口的名称

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

希望这能澄清您的观点。

代码如下

static bool isExpanded = false;
我认为Window1是添加列表视图控件的窗口的名称

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

希望这能澄清你的观点。

谢谢你的回复,你能更详细一点吗?谢谢你的回复,你能更详细一点吗?如果我没有弄错的话,这只会触发所有组被折叠或扩展,而不是由GroupDescription生成的特定组,或者我错了?是的,我可能错了,但我只是建议您解决方案您可以为每个组创建一个扩展标志的静态列表,在Window_load中,您可以检索这些值并将其分配给每个组的扩展属性。。希望这可以解决你的问题,如果需要进一步的帮助,请寻求帮助。如果你想让我给你工作的解决方案,那么我需要一些时间。你同意吗?当然可以。我只是被群体之间的这种联系所困扰property@Xeun你有这个问题的解决方案吗?或者你需要更多的帮助吗?如果我没有弄错的话,这只会触发所有组被折叠或扩展,而不是由GroupDescription生成的特定组,或者我错了?是的,我可能错了,但我只是建议您解决方案您可以为每个组创建一个扩展标志的静态列表,在Window_load中,您可以检索这些值并将其分配给每个组的扩展属性。。希望这可以解决你的问题,如果需要进一步的帮助,请寻求帮助。如果你想让我给你工作的解决方案,那么我需要一些时间。你同意吗?当然可以。我只是被群体之间的这种联系所困扰property@Xeun你有这个问题的解决方案吗,还是需要更多的帮助??