0
UWPでユーザーコントロールを作成し、依存関係プロパティからobservableコレクションの種類のlistviewバインディングを追加しました。私は自分のビューで、私のViewModelから値をバインドして使用しました。しかし、それは動作していません。私はリストビューにエンティティがないのを見た。私のユーザーコントロールの XAML:UWP:ユーザーコントロール内の依存関係プロパティから観測可能なコレクションをバインドする
<ListView ItemsSource="{x:Bind TaskLists}"
SelectionMode="None" IsMultiSelectCheckBoxEnabled="False" Name="ListofTasks" >
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate >
<TextBlock x:Name="title" FontWeight="SemiBold"
FontSize="15" Text="{Binding Subject}" Margin="7,5,0,0" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
C#の分離コード:
<Controls:TaskList TaskLists="{Binding TodayList ,Mode=TwoWay}" />
ビューモデル::私のXAMLビューで
public ObservableCollection<TaskItem> TaskLists
{
get { return (ObservableCollection<TaskItem>)GetValue(TaskListsProperty); }
set { SetValue(TaskListsProperty, value); }
}
// Using a DependencyProperty as the backing store for TaskLists. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TaskListsProperty =
DependencyProperty.Register("TaskLists", typeof(ObservableCollection<TaskItem>), typeof(TaskList), new PropertyMetadata(null));
ユーザーコントロールの使用
class TimeLineViewModel:INotifyPropertyChanged
{
public TimeLineViewModel()
{
for (int i = 0; i < 10; i++)
{
TodayList.Add(new TaskItem() { ID = i, Detail = "Lurem IPsum Very cool app is under dev to be abnormal and very secret " + i, Subject = "This is Title of " + i
, Imprtance = 1, Isdone = 2, Notify = 1, StartTime = DateTime.Now.AddHours(2), Tags= new ObservableCollection<string>() {"Tagone" , "tagtwo","tagThree","TagFour"}
});
}
}
ObservableCollection<TaskItem> TodayList = new ObservableCollection<TaskItem>();
public event PropertyChangedEventHandler PropertyChanged;
}
どのように必要なDataContextを設定していますか? –
@PedroLamas私はそれを設定しました – Mohsen