0

我有以下 XAML,其中有两个具有相同 ItemsSource 的组合框控件。我用IsSynchronizedWithCurrentItem=False来试图让他们单独行动。但仍然改变一个改变另一个。

XAML

<Page x:Class="HaMmeR.FantasyFootball.TradeEvalPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
    Title="TradeEvalPage">
    <Grid x:Name="masterPanel">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <DockPanel Grid.Row="0" Grid.Column="0" Style="{DynamicResource dockLsLabel}">
            <Label  x:Name="teamName1Lbl" Content="Team Name" Style="{DynamicResource lsLabel}" />
            <!--IsSynchronizedWithCurrentItem=False Treat datasource as individual-->
            <ComboBox x:Name="teamName1Cmb"  Margin="2" DockPanel.Dock="Right"
                              ItemsSource="{Binding Path=FantasyTeams}"
                      IsSynchronizedWithCurrentItem="False"
                              DisplayMemberPath="TeamName"
                              SelectionChanged="teamName1Cmb_SelectionChanged"
                              SelectedValuePath="TeamName" SelectedValue="{Binding Path=TeamName}"/>
        </DockPanel>
        <DockPanel Grid.Row="0" Grid.Column="1" Style="{DynamicResource dockLsLabel}">
            <Label  x:Name="teamName2Lbl" Content="Team Name" Style="{DynamicResource lsLabel}" />
            <ComboBox x:Name="teamName2Cmb"  Margin="2" DockPanel.Dock="Right"
                              ItemsSource="{Binding Path=FantasyTeams}"
                       IsSynchronizedWithCurrentItem="False"
                              DisplayMemberPath="TeamName"
                              SelectionChanged="teamName2Cmb_SelectionChanged"
                              SelectedValuePath="TeamName" SelectedValue="{Binding Path=TeamName}"/>
        </DockPanel>
    </Grid>
</Page>

.cs 文件

 public partial class TradeEvalPage : Page
    {
        private FantasyLeague league;
        public TradeEvalPage(FantasyLeague League)
        {
            InitializeComponent();
            league = League;

            //FantasyTeamCollection team1Source = new FantasyTeamCollection(league.FantasyTeams.ToList<FantasyTeam>());
            //FantasyTeamCollection team2Source = new FantasyTeamCollection(league.FantasyTeams.ToList<FantasyTeam>());
            //teamName1Cmb.DataContext = team1Source;
            //teamName2Cmb.DataContext = team2Source;
            masterPanel.DataContext = league;


            //mainContent.Text = string.Format("You clicked Trade Evalution of {0}", league.LeagueName);
        }
     }

我无法弄清楚我做错了什么。任何帮助,将不胜感激。

4

1 回答 1

1

我认为是因为您将 selectedValue 绑定到 TeamName。

SelectedValue="{绑定路径=团队名称}"

如果您删除绑定,它们可能会起作用。我认为这里发生的情况是,当您在一个组合框中更改选择时,新选定项目的值将写入当前项目名称中。所以看起来第一个组合框的作用是一样的,但是如果你打开它,你会看到这个值两次。

于 2013-08-27T21:09:32.047 回答