Как мне запустить этот метод класса?
Я определил XAML-окно:
<pre><Window x:Class="latex_curriculum_vitae.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:latex_curriculum_vitae" mc:Ignorable="d" Title="Latex Curriculum Vitae" Height="450" Width="800"> <Grid> <Label Content="Jobtitle of your application:" HorizontalAlignment="Left" Margin="64,52,0,0" VerticalAlignment="Top"/> <Label Content="Enter Company Name:" HorizontalAlignment="Left" Margin="64,83,0,0" VerticalAlignment="Top"/> <Label Content="Enter companies street:" HorizontalAlignment="Left" Margin="64,109,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.52,-0.663"/> <Label Content="ZIP Code:" HorizontalAlignment="Left" Margin="64,135,0,0" VerticalAlignment="Top"/> <Label Content="City:" HorizontalAlignment="Left" Margin="475,135,0,0" VerticalAlignment="Top"/> <TextBox x:Name="txtJobtitle" HorizontalAlignment="Left" Margin="318,60,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="428"/> <TextBox x:Name="txtCompanyName" HorizontalAlignment="Left" Margin="318,87,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="428" RenderTransformOrigin="0.042,0.295"/> <TextBox x:Name="txtCompanyStreet" HorizontalAlignment="Left" Margin="318,113,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="428" RenderTransformOrigin="0.517,-0.986"/> <TextBox x:Name="txtZIP" HorizontalAlignment="Left" Margin="318,139,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/> <TextBox x:Name="txtCity" HorizontalAlignment="Left" Margin="544,139,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="202"/> <Separator HorizontalAlignment="Left" Margin="64,166,0,0" VerticalAlignment="Top" Height="25" Width="701" RenderTransformOrigin="0.501,1.041"/> <Label Content="About Company" HorizontalAlignment="Left" Margin="64,21,0,0" VerticalAlignment="Top" FontWeight="Bold"/> <Label Content="About Contact person" HorizontalAlignment="Left" Margin="64,191,0,0" VerticalAlignment="Top" FontWeight="Bold"/> <Label Content="Name:" HorizontalAlignment="Left" Margin="356,237,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.655,0.05"/> <ComboBox x:Name="cboGender" HorizontalAlignment="Left" Margin="166,237,0,0" VerticalAlignment="Top" Width="120" RenderTransformOrigin="0.192,-0.613"> <ComboBoxItem Content="Male"/> <ComboBoxItem Content="Female"/> <ComboBoxItem Content="Unknown"/> </ComboBox> <Label Content="Gender:" HorizontalAlignment="Left" Margin="64,235,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.401,0.29" Width="97"/> <TextBox x:Name="txtContactName" HorizontalAlignment="Left" Margin="431,241,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="315" RenderTransformOrigin="0.523,1.812"/> <Separator HorizontalAlignment="Left" Margin="64,268,0,0" VerticalAlignment="Top" Height="25" Width="701" RenderTransformOrigin="0.501,1.041"/> <Label Content="About Application" HorizontalAlignment="Left" Margin="64,293,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.783,-0.287" FontWeight="Bold"/> <Label Content="URL:" HorizontalAlignment="Left" Margin="64,324,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.105,-0.441"/> <TextBox x:Name="txtURL" HorizontalAlignment="Left" Margin="166,328,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="580"/> <Label Content="Emailaddress:" HorizontalAlignment="Left" Margin="64,355,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.171,-0.634"/> <TextBox x:Name="txtEmail" HorizontalAlignment="Left" Margin="166,359,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="266" RenderTransformOrigin="0.5,0.5"> <TextBox.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform Angle="0.086"/> <TranslateTransform/> </TransformGroup> </TextBox.RenderTransform> </TextBox> <Button x:Name="btnGenerate" Content="Generate" HorizontalAlignment="Left" Margin="549,384,0,0" VerticalAlignment="Top" Width="96"/> <Button x:Name="btnExit" Content="Exit" HorizontalAlignment="Left" Margin="669,384,0,0" VerticalAlignment="Top" Width="96"/> </Grid> </Window>
Также у меня есть класс "пользователь":
class User { private String firstname; private String familyname; private String mystreet; private String myCity; private String myphone; private String myemail; private String myblog; public User() { firstname = ConfigurationManager.AppSettings.Get("firstname"); familyname = ConfigurationManager.AppSettings.Get("familyname"); mystreet = ConfigurationManager.AppSettings.Get("mystreet"); myCity = ConfigurationManager.AppSettings.Get("mycity"); myphone = ConfigurationManager.AppSettings.Get("myphone"); myemail = ConfigurationManager.AppSettings.Get("myemail"); myblog = ConfigurationManager.AppSettings.Get("myblog"); DebugSettings(); UserFile(); } private void UserFile() { string[] lines = { "\\def\\firstname{" + firstname + "}", "\\def\\familyname{" + familyname + "}" , "\\def\\mystreet{" + mystreet + "}", "\\def\\mycity{" + myCity + "}", "\\def\\myphone{" + myphone + "}", "\\def\\myemail{" + myemail + "}", "\\def\\myblog{" + myblog + "}" }; // Set a variable to the Documents path. string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); // Write the string array to a new file named "WriteLines.txt". using (StreamWriter outputFile = new StreamWriter(Path.Combine(appDataPath, "personal_data.tex"))) { foreach (string line in lines) outputFile.WriteLine(line); } } private void DebugSettings() { string[] settings = { firstname, familyname, mystreet, myCity, myphone, myemail, myblog }; foreach (string setting in settings) Console.WriteLine(setting); } }
В главном окне я использую:
private void btnGenerate_Click(object sender, EventArgs e) { User myuser = new User(); }
В общем, я ожидаю, что после нажатия на кнопку "btnGenerate" он запускает методы DebugSettings и UserFile.
Но в настоящее время он выглядит так, как будто не выводит настройки и не сохраняет файл.
Я что-нибудь пропустил?
Что я уже пробовал:
Тоже погуглил, но ничего не нашел :-(
Richard MacCutchan
Вы можете проверить, что происходит, когда вы запускаете его, используя отладчик и шагая через код. Обратите внимание, что приложение WPF не имеет консоли, поэтому ни одна из этих консолей.WriteLine(настройка); операторы будут делать все, что угодно.