2016-09-29 9 views
0

UWPアプリケーションを作成していて、コンボボックスがいくつかビューモデルにバインドされています。何らかの理由で、コンボボックスは、デバッグ中に手動で値を設定すると、バインドされた値を更新したり、レンダリング時にロードしたりしません。私はこれが共通の問題であることを知っていますが、他の人がこれまでに見てきた原因を見つけることはできません。UWPコンボボックスにバインド値が設定されていません

XAML:

<Page 
x:Class="UWPApp.Scorekeeper.SelectGoalTime" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:UWPApp.Scorekeeper" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
x:Name="MainElement"> 

<Grid Background="{ThemeResource SystemControlBackgroundAccentBrush}"> 
    <ComboBox x:Name="MinutesSelect" SelectedValue="{Binding ElementName=MainElement,Path=ViewModel.Minutes}" ItemsSource="{Binding ElementName=MainElement,Path=MinutesList}"/> 
</Grid> 

C#

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Windows.Input; 
using Windows.UI.Xaml.Controls; 
using Windows.UI.Xaml.Navigation; 
using UWPApp.Scorekeeper.Interfaces; 
using UWPApp.Scorekeeper.Models.ViewModels; 
using UWPApp.Scorekeeper.Models.TransportClasses; 
using Windows.UI.Popups; 
using UWPApp.Scorekeeper.Models; 
using UWPApp.Scorekeeper.Toolbox; 

namespace UWPApp.Scorekeeper 
{ 
    public sealed partial class SelectGoalTime : Page 
    { 
     public AddGoal_FVM ViewModel { get; set; } 

     public List<int> MinutesList { get; set; } = Enumerable.Range(0,21).ToList(); 

     public SelectGoalTime() 
     { 
      this.InitializeComponent(); 
     } 

     protected override void OnNavigatedTo(NavigationEventArgs e) 
     { 
      var message = e.Parameter as GoalMessage; 
      ViewModel = message.ViewModel; 
     } 
    } 
} 

AddGoal_FVM

、次は私のコードをストリップダウンされます
+0

INotifyPropertyChangedを使用する場合は、boundedプロパティのsetterでNotifyPropertyChangedを呼び出す必要があります。public int Minutes {set {NotifyPropertyChanged();}} SelectGoalTimeクラスにDataContextを設定する必要があります。 –

+0

その実装を削除するのを忘れてしまいました。値がページの読み込みと選択以外で変更されていないため(つまり、このプロパティにはINotifyPropertyChanged実装が必要ないため)、この問題には影響しません。それが必要な場合、DataContextを設定せずにリストバインディングが機能するのはなぜですか? – Ceshion

答えて

0

私がコメントを追加するための評判を持っていないので、私はこの方法を共有する必要があります:ここで見つける

https://twitter.com/kdawg02/status/746734845393518592、BUG UWPコンボボックスSelectedValueのは、XAMLの最後のプロパティである必要があり、それ以外の場合負荷時に値を設定しません。

MVVMパターンでUWPのコンボボックスをバインドしようとすると、困ったことがありません。

+0

残念ながら、これは修正されていないようです。それは、ビューモデルの値を読み込んでいるようですが、設定していません。 – Ceshion

関連する問題