abdujalil  chuliev

abdujalil chuliev

  • 1.3k
  • 400
  • 38.9k

Accessing the MainWindow class tools by other c# classes

Jun 10 2016 7:04 AM
I need to access textbox and label controls for other c# classes(not only MainWindow class) in wpf.
I used x:FieldModifier="public" but still negative.
Is it possible to populate MainWindow class Tools for other classes?
Here is my simplified example code:
 
<Window x:Class="MyAbsClass.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:MyAbsClass"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox x:FieldModifier="public" x:Name="txt1"/>
<TextBox x:FieldModifier="public" x:Name="txt2"/>
<Button x:FieldModifier="public" x:Name="btn1" Content="Button" Click="btn1_Click"/>
</Grid>
</Window>
 
namespace MyAbsClass
{
class manipulate
{
public void add()
{
int a=int32.Parse(txt1.Text);
int b=int32.Parse(txt2.Text);
}
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btn1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Added value= "+(a+b));
}
}
}

Answers (1)