2

私は数秒ごとに参加者の新しい ObservableCollection を取得します - ビューの取得はすべて正常に更新されます.秒)必要なアイテムを選択します(強調表示します)が、機能しません。選択をクリアします/ SelectedParticipant が設定された後、選択/強調表示が表示されません

  • はい、もちろん、SelectedParticipant が null ではないことを確認しました
  • LayoutUpdate() またはそのようなものを試しました
  • SelectedItem="{Binding SelectedParticipant, Mode=TwoWay}" 内で UpdateSourceTrigger=PropertyChanged を試しました

ありがとう

    private Participant _selectedParticipant;
    public Participant SelectedParticipant
    {
        get
        {
            return _selectedParticipant;
        }
        set
        {
            if (_selectedParticipant != value)
            {
                _selectedParticipant = value;

                RaisePropertyChanged("SelectedParticipant");
            }
        }
    }

    private ObservableCollection<Participant> _participants;
    public ObservableCollection<Participant> Participants
    {
        get
        {
            return _participants;
        }
        set
        {
            if (_participants != value)
            {
                _participants = value;

                RaisePropertyChanged("Participants");

                if (_participants != null && _participants.Count > 0)
                {
                    SelectedParticipant = null;

                    SelectedParticipant = Participants.FirstOrDefault(x => ... );

                }

            }
        }
    }

<ListBox ItemsSource="{Binding Participants}"
             SelectedItem="{Binding SelectedParticipant, Mode=TwoWay}"
             ItemContainerStyle="{StaticResource RedGlowItemContainer}" 
             ScrollViewer.HorizontalScrollBarVisibility="Disabled"  
             Background="Transparent" 
             Padding="25">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Border  BorderThickness="6" >
                    <Grid>
                       <Image Source="{Binding Client.ImageURL}"  VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Fill" Width="128" Height="128"/>
                    </Grid>
                </Border>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
4

1 に答える 1

1

参加者に値を割り当てる代わりに、クリアして追加します。これは単なる試行です

public class ViewModel
{
    public ObservableCollection<Participant> Participants { get; set; }

    public ViewModel()
    {
        Participants = new ObservableCollection<Participant>();
    }

    public void UpdateParticipants(IEnumerable<Participant> participants)
    {
        Participants.Clear();
        if (participants.Any())
        {
            foreach (var participant in participants)
            {
                Participants.Add(participant);
            }
            SelectedParticipant = Participants.First();
        }
    }
}

これが役立つことを願っています。

于 2013-08-08T08:49:35.087 に答える