Wpf Caliburn.Micro-将组合框项目传递到按钮
我试图将项目从我的组合框(绑定到模型对象的列表)传递到我的按钮。我的问题是,我是Caliburn.Micro+WPF新手,不太确定如何订阅/传递所需的值到我的按钮(比如将PropertyName的字符串发送到按钮(string PropertyName)) 视图模型代码:Wpf Caliburn.Micro-将组合框项目传递到按钮,wpf,caliburn.micro,Wpf,Caliburn.micro,我试图将项目从我的组合框(绑定到模型对象的列表)传递到我的按钮。我的问题是,我是Caliburn.Micro+WPF新手,不太确定如何订阅/传递所需的值到我的按钮(比如将PropertyName的字符串发送到按钮(string PropertyName)) 视图模型代码: class ShellViewModel : Screen { private DataModel _fileInFolder; private BindableCollection<DataModel&
class ShellViewModel : Screen
{
private DataModel _fileInFolder;
private BindableCollection<DataModel> _data;
public ShellViewModel()
{
// .GetData() preforms the objects' initialization
DataModel dataOutput = new DataModel();
Data = new BindableCollection<DataModel>(dataOutput.GetData());
}
public BindableCollection<DataModel> Data
{
get
{
return _data;
}
set
{
_data = value;
NotifyOfPropertyChange(() => Data);
}
}
public DataModel FileInFolder
{
get { return _fileInFolder; }
set
{
_fileInFolder = value;
NotifyOfPropertyChange(() => FileInFolder);
}
}
//This is where the items will be passed to.
public void OpenFile()
{
}
}
类ShellViewModel:屏幕
{
私有数据模型_fileInFolder;
私有BindableCollection_数据;
公共ShellViewModel()
{
//.GetData()执行对象的初始化
DataModel dataOutput=新的DataModel();
Data=newbindablecolection(dataOutput.GetData());
}
公共BindableCollection数据
{
得到
{
返回数据;
}
设置
{
_数据=价值;
NotifyOfPropertyChange(()=>数据);
}
}
公共数据模型文件文件夹
{
获取{return\u fileInFolder;}
设置
{
_fileInFolder=value;
NotifyOfPropertyChange(()=>FileInFolder);
}
}
//这是项目将传递到的位置。
公共void OpenFile()
{
}
}
XAML代码:
<Grid>
<!-- Folders -->
<ComboBox ItemsSource="{Binding Data}" SelectedItem="{Binding FileInFolder}"
HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="250">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Folders}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- Files -->
<ComboBox x:Name="FileInFolder_Files"
HorizontalAlignment="Left" Margin="280,10,0,0" VerticalAlignment="Top" Width="250"/>
<!-- Open File -->
<Button x:Name="OpenFile"
Content="Open File" HorizontalAlignment="Left" Margin="560,10,0,0" VerticalAlignment="Top" Width="90">
</Button>
</Grid>
抱歉,如果我的描述含糊不清/缺少更多说明,我是这里的新用户 FileInFolder是组合的选定项 OpenFile在同一个类中,因此可以引用FileInFolder
public void OpenFile()
{
var whatever = FileInFolder.SomeProperty;
// etc
}
您可能需要在那里进行一些空检查