我做了一个Toggle,它扩展了一个弹出式窗口,里面有一个ListBox。看起来是这样的:
<ToggleButton Name="Toggle" Height="20" Width="150" >
<StackPanel>
<TextBlock Text="TestListPopup"/>
<Popup Height="200" Width="150"
IsOpen="{Binding ElementName=Toggle, Path=IsChecked}"
PlacementTarget="{Binding ElementName=Toggle}"
HorizontalAlignment="Left"
VerticalAlignment="Bottom">
<ListBox SelectionMode="Multiple" SelectionChanged="TypeSelectionChanged" >
<ListBoxItem Content="Test1"/>
<ListBoxItem Content="Test2"/>
<ListBoxItem Content="Test3"/>
</ListBox>
</Popup>
</StackPanel>
</ToggleButton>它工作得很好,但是我想在我的xceed FilterRow的DataGrid中使用它:
<xcdg:DataGridControl x:Name="dataGrid"
ItemsSource="{Binding Source={StaticResource DataSource}}">
<xcdg:DataGridControl.View>
<xcdg:TableflowView>
<xcdg:TableflowView.FixedHeaders>
<DataTemplate>
<xcdg:ColumnManagerRow/>
</DataTemplate>
<DataTemplate>
<xcdg:FilterRow>
<xcdg:FilterCell FieldName="Name" IsEnabled="True"/>
<xcdg:FilterCell FieldName="Type" IsEnabled="True">
<!-- TestListPopup control here -->
</xcdg:FilterCell>
</xcdg:FilterRow>
</DataTemplate>
</xcdg:TableflowView.FixedHeaders>
</xcdg:TableflowView>
</xcdg:DataGridControl.View>
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="Name" Title="Name" />
<xcdg:Column FieldName="Type" Title="Type" Width="160"/>
</xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>但是在这里,弹出窗口将不会绑定到切换按钮。按下按钮什么也做不了。
我将范围缩小到绑定被破坏,因为如果您设置IsOpen="True",它是打开的(而不是依附于PlacementTarget),但还是一样;它在DataGrid之外工作得非常好。
为什么一个功能完善的控件一旦放入FilterRow就会中断呢?
如有任何帮助,将不胜感激!)
发布于 2018-11-08 12:50:54
为什么一个功能完善的控件一旦放入
FilterRow就会中断呢?
因为ToggleButton和FilterCell不属于同一个显象管。
您可以尝试使用x:Reference绑定
IsOpen="{Binding Path=IsChecked, Source={x:Reference Toggle}}"另一个选项是将ToggleButton的ToggleButton属性绑定到视图模型的bool属性,并将Popup的IsOpen属性绑定到相同的源属性。确保视图模型实现INotifyPropertyChanged接口,并在设置源属性时引发更改通知。
https://stackoverflow.com/questions/53206739
复制相似问题