WPF operation after filling camps


WPF operation after filling camps



I'm quite new to c#, especially for application with an interface. I looked for example or guide on WPF but they are too simple. Here is what I would to do:


WPF



1) a button to browse on directory and select files;



2) a Listbox and a textBox will be filled using info by the filenames selected previously;


Listbox


textBox



3) rename those files by web info only when Listbox and textbox are filled.


Listbox


textbox



Point 1) and 2) are done: I wrote the necessary code inside click button event. I was thinking to write code for point 3) inside MainWindow but those lines of code are carried out before I can select files, then there isn't any data yet.


MainWindow



The easy solution could be to insert the rest of the code inside the click button event too, but I think it's horrible. At the moment I can't understand what to write in the MAIN on a WPF app.
The code is:


WPF


public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void webLink_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.battlecraft.it/");
}

private void loader_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
ofd.ShowDialog();
listBox1.Items.Clear();
string files = ofd.FileNames;
string filenames = new string[files.Length];
for (int i=0; i<files.Length; i++)
{
filenames[i] = System.IO.Path.GetFileNameWithoutExtension(files[i]);
listBox1.Items.Add(filenames[i]);
}
if (listBox1.Items.Count != 0)
{
string SeEp = Regex.Match(filenames[0], @"d+wd+").Value;
string str = Regex.Split(filenames[0], @"ddw+dd");
string titolo = str[0].Replace(".", " ");

MatchCollection m = Regex.Matches(SeEp, @"dd");
titleBox.Text = titolo;
seasonBox.Text = "stagione " + m[0].Value;
int episode = int.Parse(m[1].Value);
}
}
}





This would be quite a bit cleaner if you utilized the MVVM pattern and encapsulated out certain functionality (like the file selection).
– BradleyDotNET
Jun 28 at 15:58




1 Answer
1



I've just learnt the concept of Binding and this should solve my problem. Binding the IsEnabled property of the startBtn to the Length of listbox1 and listbox2 should disable the button when they are empty and enable it otherwise.



I created a simple bind only between startBtn and listbox1 like following:


<Button x:Name="startBtn" Content="Rinomina" HorizontalAlignment="Left" Margin="255,79,0,0" VerticalAlignment="Top" Width="75" Height="36" IsEnabled="{Binding ElementName=listBox1, Path=Text.Length}"/>



and it works without adding any line of code in c#. I should use MultiBinding but I can't understand the syntax to pass 2 textboxes. Is it also possible without write any code in c#?






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift