【发布时间】:2022-01-11 11:07:56
【问题描述】:
我在一个窗口上有我的 userControl 元素,现在我必须将这些 userControls 内的组合框连接到 ViewModel 上的 ObcervableCollections。但我不能。我将集合链接到项目,但出现以下错误 - 当我在一个组合框中更改选择时,我会自动获取其他组合框中的更改。如何取消绑定组合框的 SelectedItem 以将 1 个集合用于具有独立选择的多个项目。我的控件有这个接口(例如)。
<uielements:DeviceParametersControl Grid.Column="1"
Margin="2,2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
EndColor="#3B191919"
NumberOfSystem="2"
MaxFaultPressureValue="{Binding DataContext.SelectedParameter[1].MaxFaultPressureValue, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
MaxWorkPressureValue="{Binding DataContext.SelectedParameter[1].MaxWorkPressureValue, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
MinWorkPressureValue="{Binding DataContext.SelectedParameter[1].MinWorkPressureValue, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
TestTimeValue="{Binding DataContext.SelectedParameter[1].TestTimeValue, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
PulseTimeValue="{Binding DataContext.SelectedParameter[1].PulseTimeValue, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
PauseTimeValue="{Binding DataContext.SelectedParameter[1].PauseTimeValue, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
PulsesCount="{Binding DataContext.SelectedParameter[1].PulsesCount, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
PulsesAcceleration="{Binding DataContext.SelectedParameter[1].PulsesAcceleration, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
Mode="{Binding DataContext.SelectedParameter[1].Mode,UpdateSourceTrigger=PropertyChanged, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
StartColor="#3BFFFFFF"
TestName="{Binding DataContext.SelectedParameter[1].Name, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
UpdateDataToDbCommand="{Binding DataContext.UpdateDataToDbCommand,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
UpdateDataToPlcCommand="{Binding DataContext.UpdateDataToPlcCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}"
ItemsSource="{Binding DataContext.Parameters, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
DisplayMemberPath="Value"
SelectedValuePath="Id"
SelectedValue="{Binding DataContext.SelectedItem4Two, Mode=OneWayToSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
</uielements:DeviceParametersControl>
【问题讨论】:
-
“我将集合链接到项目,但出现以下错误” - 您提到您收到“以下错误”,但实际上并未将错误粘贴到您的问题中。请更新一下好吗?