Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TagPort.Models
- {
- public class EPMConnection
- {
- public string epmServerMachine { get; set; }
- public string serverPort { get; set; }
- public string serverUser { get; set; }
- public string serverPwd { get; set; }
- }
- }
- namespace TagPort.ViewModels
- {
- class ConnectionViewModel : INotifyPropertyChanged
- {
- public EPMConnection epmConnection;
- public ConnectionViewModel()
- {
- epmConnection = new EPMConnection { epmServerMachine = "Tteste2" };
- }
- public event PropertyChangedEventHandler PropertyChanged;
- protected void RaisePropertyChanged([CallerMemberName] String propertyName = "")
- {
- if (PropertyChanged != null)
- {
- PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- public EPMConnection Connection
- {
- get { return epmConnection; }
- set
- {
- epmConnection = value;
- }
- }
- public string EpmServerMachine
- {
- get { return epmConnection.epmServerMachine; }
- set
- {
- if(epmConnection.epmServerMachine != value)
- {
- epmConnection.epmServerMachine = value;
- RaisePropertyChanged();
- }
- }
- }
- public string EpmServerPort
- {
- get { return epmConnection.serverPort; }
- set
- {
- if (epmConnection.serverPort != value)
- {
- epmConnection.serverPort = value;
- RaisePropertyChanged();
- }
- }
- }
- public string EpmServerUser
- {
- get { return epmConnection.serverUser; }
- set
- {
- if (epmConnection.serverUser != value)
- {
- epmConnection.serverUser = value;
- RaisePropertyChanged();
- }
- }
- }
- public string EpmServerPwd
- {
- get { return epmConnection.serverPwd; }
- set
- {
- if (epmConnection.serverPwd != value)
- {
- epmConnection.serverPwd = value;
- RaisePropertyChanged();
- }
- }
- }
- public string ConnectionToString()
- {
- string p1 = (" EpmServer:"+ EpmServerMachine + "n EpmPort:" + EpmServerPort + " n EpmUser:" + EpmServerUser + " n EpmPwd" + EpmServerPwd + "");
- return p1;
- }
- }
- }
- <UserControl.Resources>
- <local:ConnectionViewModel x:Key="ConnectionVM"/>
- </UserControl.Resources>
- <Grid DataContext="{StaticResource ConnectionVM}">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="180"></ColumnDefinition>
- <ColumnDefinition Width="*"></ColumnDefinition>
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="34"></RowDefinition>
- <RowDefinition Height="34"></RowDefinition>
- <RowDefinition Height="34"></RowDefinition>
- <RowDefinition Height="34"></RowDefinition>
- <RowDefinition Height="34"></RowDefinition>
- </Grid.RowDefinitions>
- <Label Content="EPM Sever Machine:" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0"/>
- <Label Content="EPM Server Port:" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="1"/>
- <Label Content="EPM Server User:" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="2"/>
- <Label Content="EPM Server Password:" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="3"/>
- <TextBox TextWrapping="Wrap" Text="{Binding EpmServerMachine,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" Height="23" Margin="0,0,4,0"/>
- <TextBox TextWrapping="Wrap" Text="{Binding EpmServerPort,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Height="23" Margin="0,0,4,0"/>
- <TextBox TextWrapping="Wrap" Text="{Binding EpmServerUser,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Height="23" Margin="0,0,4,0"/>
- <TextBox TextWrapping="Wrap" Text="{Binding EpmServerPwd,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" Height="23" Margin="0,0,4,0"/>
- <Button Content="Test Connection" Grid.Column="1" Grid.Row="4" Width="Auto" HorizontalAlignment="Right" Height="23" VerticalAlignment="Bottom" Margin="0,0,4,0" Click="TestConnection_Click"/>
- </Grid>
- public partial class EPMConnectionTab : UserControl
- {
- ConnectionViewModel _viewModel;
- public EPMConnectionTab()
- {
- InitializeComponent();
- _viewModel = new ConnectionViewModel();
- this.DataContext = _viewModel;
- }
- private void TestConnection_Click(object sender, RoutedEventArgs e)
- {
- MessageBox.Show(_viewModel.ConnectionToString());
- }
- }
Add Comment
Please, Sign In to add comment