これは私を困惑させました-うまくいけば、誰かが明らかなエラーを指摘することができます。プログラムのMainViewのグリッドに追加するユーザーコントロールがあります。メインビューはMainViewModelにバインドされ、ユーザーコントロールはCardioVMにバインドされます。
テストラベルを使用して、ユーザーコントロールのルーティングが正しく、すべて正常に機能していることを確認しました。Cardioという名前のクラスがあります。
List<string> exercises
文字列を渡そうとしています
Cardio.List<string> exercises
に
List<string> CardioList
私のCardioVMで。デバッグ時
List<string> CardioList
からのアイテムが入力されています
Cardio.List<string> exercises
しかし、私のComboBoxは画面にアイテムを表示していません。これが私のUserControlのxamlと:
<UserControl x:Class="CalendarTest.UserControl1"
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"
DataContext="{Binding CardioVM, Source={StaticResource Locator}}">
<Grid>
<ComboBox ItemsSource="{Binding CardioList, Mode=OneWay}" SelectedItem="{Binding SelectedCardio, Mode=TwoWay}" Height="50"></ComboBox>
</Grid>
これが私のCardioVMのコードです。
public class CardioVM : ViewModelBase
{
public Cardio cardioItem { get; set; }
public CardioVM()
{
TestLabel = "Tester";
}
//Test Label for binding testing
private string testLabel;
public string TestLabel
{
get { return testLabel; }
set
{
testLabel = value;
RaisePropertyChanged("TestLabel");
}
}
public CardioVM(string Date, string File)
{
cardioItem = new Cardio(File, Date);
CardioList = new List<string>(cardioItem.exercises);
}
private List<string> cardioList;
public List<string> CardioList
{
get { return cardioList; }
set
{
cardioList = value;
RaisePropertyChanged("CardioList");
}
}
private string _selectedCardio;
public string SelectedCardio
{
get { return _selectedCardio; }
set
{
_selectedCardio = value;
RaisePropertyChanged("SelectedCardio");
}
}
}
}
ここでどこが間違っているのかわかりませんが、ポインタをいただければ幸いです。
これが、メインビューモデルのコンテンツコントロールバインドプロパティにuserControlを追加しようと思った場所です。
public void NewTemplateExecute()
{
TextHideTab = "Close";
NewTemplateType = ("New " + SelectedExercise + " Exercise Template");
//Set the message and lists based on the exercise selected plus adds the drop down control
switch (SelectedExercise)
{
case "Cardio":
///
//This is where I thought CardioVM was being added
///
NewTemplateText = "Please choose a cardio exercise from the drop down list to the left. You can then select the duration of the exercise and the intensity. To add another exercise please press the plus button in the right hand corner";
ExerciseDropDowns = new CardioVM(selectedDateLabel, @"Model\Repository\Local Data\CardioList.txt");
break;
case "Weights":
NewTemplateText = "Please select a exercise type. you can refine your exercises by body area. Then add the number of sets and the reps per set. Add as many exercises as you like - dont forget to set to total duration";
break;
case "HIIT":
NewTemplateText = "HIIT to add";
break;
}
Messenger.Default.Send("NewTemplate");
}
MainwindowxamlでCardioVMのデータコンテキストを次のように設定しました。
<DataTemplate DataType="{x:Type local:CardioVM}">
<view:UserControl1/>
</DataTemplate>
CaridoVMを接続する方法を間違えたと思いますが、VMロケーターを介して送信しない限り、データバインドに取得できなかったようです。