Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,
am new by C#.net WPF MVVM and i try to save a filename that i have got using a buttoncommand. i get the filename but the Problem is i've to do it everytime. i want to save the filename in the Combobox using a list so that i can't click to the button a second time to get it.

please excuse me for my english and thank you your help.

What I have tried:

<stackpanel orientation="Horizontal" grid.column="2" grid.row="1">
<Button Content="..." Command="{Binding SelectfilenameCommand}"
ToolTip=" wähle filename aus" Grid.Column="1" Grid.Row="1"
HorizontalAlignment="Left" Width="30" Height="20" Margin="5,1.667,5,10.333" ></Button>

<combobox name="Combo" itemssource="{Binding DataModel.ExeDateiList}" selecteditem="{Binding DataModel.DataConfig.SelectedExeDatei, Mode=TwoWay }" text="filename" horizontalalignment="Center" width="Auto" iseditable="True" isreadonly="True" margin="5,2,5,10">



My ViewModel Code:
public void Selectfilename()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Prozess (*.*)|*.*";
if (ofd.ShowDialog() == true)
{
string filename= Path.GetFileName(ofd.FileName);

this.ExeDateiList.Add(filename);

}
}
Posted
Updated 1-Jun-16 2:17am
v2

1 solution

Did you bind ExeDateiList to your combo box? Then only raise the PropertyChanged event for that property after adding the newly selected filename to the list.
By the way, opening a dialog from a ViewModel is not a good way of doing things with MVVM.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900