问题描述
我有一个longlistselector,其模板需要在app bar按钮点击时更改。还有appbar模板更改 点击按钮也是如此。在.cs文件中使用按钮点击非常容易
I have a longlistselector whose template need to change on app bar button click. Also appbar template changes with button click too. inside .cs file of view it was pretty easy using button click
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
DataTemplate dt;
dt = (DataTemplate)this.Resources["NewTemplateSelection"]; //new template to apply
list.ItemTemplate = dt;
this.ApplicationBar = this.Resources["selectmodeAppBar"] as ApplicationBar; //new
template for app bar
}
tample都在page.resource内。 我正在尝试使用MVVM Light来使用MVVM模式。但是无法在ViewModel中创建命令我是mvvm的新手,
both tample are inside page.resource. I am trying to use MVVM pattern using MVVM Light. But not able to create a command in ViewModel I am new to mvvm,
private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
{
var vm = (ViewModel)DataContext;
vm.SelectionCommand.Execute(null);
}
在viewmodel中
inside viewmodel
SelectionCommand = new RelayCommand(() =>
{
// DataTemplate dt;
// dt = (DataTemplate) email.Resources["ViewEmailTemplateSelection"];
// email.list.ItemTemplate = dt;
// email.ApplicationBar.IsVisible = false;
//email.ApplicationBar = email.Resources["selectmodeAppBar"] as ApplicationBar;
//}
});
有没有办法做到这一点,我试图将longlistselector的Itemtemplate绑定到字符串在viewmodel但我认为不允许在WP8中绑定staticresource。请提供一些在Viewmodel中执行操作的方法。
is there a way to do it , I tried to bind Itemtemplate of longlistselector with string in viewmodel but i think it s not allowed to bind staticresource in WP8. Please suggest some way to do action in Viewmodel.
推荐答案
。
实现Windows Phone 7 DataTemplateSelector和CustomDataTemplateSelector
问候。
这篇关于数据模板从viewmodel更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!