Accessing a component in a ViewModel C#
up vote
1
down vote
favorite
I have a class that extends ViewModelBase
in C#. There is already a trigger on a checkbox:
public bool PrintPackingCode
{
get
{
return this.reportConfiguration.PrintPackingCode;
}
set
{
this.reportConfiguration.PrintPackingCode = value;
this.OnPropertyChanged("PrintPackingCode");
}
}
I want to hook into that event and render a GroupBox
to disable, yet I can't find a way to access the GroupBox. In the .xaml
I gave my Box a name of PackingcodeGroupBox
. All methods and hint I found weren't aplieable. My tries inculded:
Direct Access: PackingcodeGroupBox.Enabled = false;
Using a x:Name
this.Resources["mykey"]
Here some more Code:
//At program start assign the view it's view model:
new SmlKonfigurationWindow(new SmlKonfigurationWindowVm(reportConfiguration, smlKonfigurationDialogVm));
public SmlKonfigurationWindow(ISmlKonfigurationWindowVm viewModel)
{
this.DataContext = viewModel;
this.viewModel = viewModel;
this.InitializeComponent();
this.ShowDialog();
}
The xaml:
<CheckBox Content="Content" IsChecked="{Binding Path=PrintPackingCode, UpdateSourceTrigger=PropertyChanged}" Name="PrintPackingCode"/>
<GroupBox Header="Verpackungscode" Name="VerpackungscodeGroupbox">
//Stuff to be disabled
</GroupBox>
c# xaml viewmodel
add a comment |
up vote
1
down vote
favorite
I have a class that extends ViewModelBase
in C#. There is already a trigger on a checkbox:
public bool PrintPackingCode
{
get
{
return this.reportConfiguration.PrintPackingCode;
}
set
{
this.reportConfiguration.PrintPackingCode = value;
this.OnPropertyChanged("PrintPackingCode");
}
}
I want to hook into that event and render a GroupBox
to disable, yet I can't find a way to access the GroupBox. In the .xaml
I gave my Box a name of PackingcodeGroupBox
. All methods and hint I found weren't aplieable. My tries inculded:
Direct Access: PackingcodeGroupBox.Enabled = false;
Using a x:Name
this.Resources["mykey"]
Here some more Code:
//At program start assign the view it's view model:
new SmlKonfigurationWindow(new SmlKonfigurationWindowVm(reportConfiguration, smlKonfigurationDialogVm));
public SmlKonfigurationWindow(ISmlKonfigurationWindowVm viewModel)
{
this.DataContext = viewModel;
this.viewModel = viewModel;
this.InitializeComponent();
this.ShowDialog();
}
The xaml:
<CheckBox Content="Content" IsChecked="{Binding Path=PrintPackingCode, UpdateSourceTrigger=PropertyChanged}" Name="PrintPackingCode"/>
<GroupBox Header="Verpackungscode" Name="VerpackungscodeGroupbox">
//Stuff to be disabled
</GroupBox>
c# xaml viewmodel
Why don't you bind GroupBox.IsEnabled to this property?
– Rob
Nov 8 at 11:48
I would, if you'd knew how it works
– Peter
Nov 8 at 12:03
Post some xaml snippets from you code and show us the code where you assign the viewModel
– Rob
Nov 8 at 12:04
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a class that extends ViewModelBase
in C#. There is already a trigger on a checkbox:
public bool PrintPackingCode
{
get
{
return this.reportConfiguration.PrintPackingCode;
}
set
{
this.reportConfiguration.PrintPackingCode = value;
this.OnPropertyChanged("PrintPackingCode");
}
}
I want to hook into that event and render a GroupBox
to disable, yet I can't find a way to access the GroupBox. In the .xaml
I gave my Box a name of PackingcodeGroupBox
. All methods and hint I found weren't aplieable. My tries inculded:
Direct Access: PackingcodeGroupBox.Enabled = false;
Using a x:Name
this.Resources["mykey"]
Here some more Code:
//At program start assign the view it's view model:
new SmlKonfigurationWindow(new SmlKonfigurationWindowVm(reportConfiguration, smlKonfigurationDialogVm));
public SmlKonfigurationWindow(ISmlKonfigurationWindowVm viewModel)
{
this.DataContext = viewModel;
this.viewModel = viewModel;
this.InitializeComponent();
this.ShowDialog();
}
The xaml:
<CheckBox Content="Content" IsChecked="{Binding Path=PrintPackingCode, UpdateSourceTrigger=PropertyChanged}" Name="PrintPackingCode"/>
<GroupBox Header="Verpackungscode" Name="VerpackungscodeGroupbox">
//Stuff to be disabled
</GroupBox>
c# xaml viewmodel
I have a class that extends ViewModelBase
in C#. There is already a trigger on a checkbox:
public bool PrintPackingCode
{
get
{
return this.reportConfiguration.PrintPackingCode;
}
set
{
this.reportConfiguration.PrintPackingCode = value;
this.OnPropertyChanged("PrintPackingCode");
}
}
I want to hook into that event and render a GroupBox
to disable, yet I can't find a way to access the GroupBox. In the .xaml
I gave my Box a name of PackingcodeGroupBox
. All methods and hint I found weren't aplieable. My tries inculded:
Direct Access: PackingcodeGroupBox.Enabled = false;
Using a x:Name
this.Resources["mykey"]
Here some more Code:
//At program start assign the view it's view model:
new SmlKonfigurationWindow(new SmlKonfigurationWindowVm(reportConfiguration, smlKonfigurationDialogVm));
public SmlKonfigurationWindow(ISmlKonfigurationWindowVm viewModel)
{
this.DataContext = viewModel;
this.viewModel = viewModel;
this.InitializeComponent();
this.ShowDialog();
}
The xaml:
<CheckBox Content="Content" IsChecked="{Binding Path=PrintPackingCode, UpdateSourceTrigger=PropertyChanged}" Name="PrintPackingCode"/>
<GroupBox Header="Verpackungscode" Name="VerpackungscodeGroupbox">
//Stuff to be disabled
</GroupBox>
c# xaml viewmodel
c# xaml viewmodel
edited Nov 8 at 12:13
asked Nov 8 at 11:20
Peter
944929
944929
Why don't you bind GroupBox.IsEnabled to this property?
– Rob
Nov 8 at 11:48
I would, if you'd knew how it works
– Peter
Nov 8 at 12:03
Post some xaml snippets from you code and show us the code where you assign the viewModel
– Rob
Nov 8 at 12:04
add a comment |
Why don't you bind GroupBox.IsEnabled to this property?
– Rob
Nov 8 at 11:48
I would, if you'd knew how it works
– Peter
Nov 8 at 12:03
Post some xaml snippets from you code and show us the code where you assign the viewModel
– Rob
Nov 8 at 12:04
Why don't you bind GroupBox.IsEnabled to this property?
– Rob
Nov 8 at 11:48
Why don't you bind GroupBox.IsEnabled to this property?
– Rob
Nov 8 at 11:48
I would, if you'd knew how it works
– Peter
Nov 8 at 12:03
I would, if you'd knew how it works
– Peter
Nov 8 at 12:03
Post some xaml snippets from you code and show us the code where you assign the viewModel
– Rob
Nov 8 at 12:04
Post some xaml snippets from you code and show us the code where you assign the viewModel
– Rob
Nov 8 at 12:04
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
IsEnabled is ambiental property which means that if you disable the GroupBox all controls inside that group box will also be disabled.
Try to add a binding on GroupBox like so:
IsEnabled="{Binding PrintPackingCode}"
You can also bind IsEnabled to check box if you give name to the check box.
<CheckBox x:Name="myCheckBox" .../>
<GroupBox IsEnabled="{Binding ElementName=myCheckBox, Path=IsChecked}"/>
add a comment |
up vote
1
down vote
On your vm create a new property say
private bool _isGroupEnabled;
public bool IsGroupEnabled
{
get
{
return _isGroupEnabled;
}
set
{
_isGroupEnabled = value;
this.OnPropertyChanged("IsGroupEnabled");
}
}
Now tie into the notify process by adjusting your set
for PrintPackingCode
set
{
this.reportConfiguration.PrintPackingCode = value;
IsGroupEnabled = !value; // reverse of packing to enable/disable.
this.OnPropertyChanged("PrintPackingCode");
}
Now bind your groupbox as such:
isEnabled = "{Binding IsGroupEnabled}"
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
IsEnabled is ambiental property which means that if you disable the GroupBox all controls inside that group box will also be disabled.
Try to add a binding on GroupBox like so:
IsEnabled="{Binding PrintPackingCode}"
You can also bind IsEnabled to check box if you give name to the check box.
<CheckBox x:Name="myCheckBox" .../>
<GroupBox IsEnabled="{Binding ElementName=myCheckBox, Path=IsChecked}"/>
add a comment |
up vote
2
down vote
accepted
IsEnabled is ambiental property which means that if you disable the GroupBox all controls inside that group box will also be disabled.
Try to add a binding on GroupBox like so:
IsEnabled="{Binding PrintPackingCode}"
You can also bind IsEnabled to check box if you give name to the check box.
<CheckBox x:Name="myCheckBox" .../>
<GroupBox IsEnabled="{Binding ElementName=myCheckBox, Path=IsChecked}"/>
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
IsEnabled is ambiental property which means that if you disable the GroupBox all controls inside that group box will also be disabled.
Try to add a binding on GroupBox like so:
IsEnabled="{Binding PrintPackingCode}"
You can also bind IsEnabled to check box if you give name to the check box.
<CheckBox x:Name="myCheckBox" .../>
<GroupBox IsEnabled="{Binding ElementName=myCheckBox, Path=IsChecked}"/>
IsEnabled is ambiental property which means that if you disable the GroupBox all controls inside that group box will also be disabled.
Try to add a binding on GroupBox like so:
IsEnabled="{Binding PrintPackingCode}"
You can also bind IsEnabled to check box if you give name to the check box.
<CheckBox x:Name="myCheckBox" .../>
<GroupBox IsEnabled="{Binding ElementName=myCheckBox, Path=IsChecked}"/>
answered Nov 8 at 12:18
Rob
1,028920
1,028920
add a comment |
add a comment |
up vote
1
down vote
On your vm create a new property say
private bool _isGroupEnabled;
public bool IsGroupEnabled
{
get
{
return _isGroupEnabled;
}
set
{
_isGroupEnabled = value;
this.OnPropertyChanged("IsGroupEnabled");
}
}
Now tie into the notify process by adjusting your set
for PrintPackingCode
set
{
this.reportConfiguration.PrintPackingCode = value;
IsGroupEnabled = !value; // reverse of packing to enable/disable.
this.OnPropertyChanged("PrintPackingCode");
}
Now bind your groupbox as such:
isEnabled = "{Binding IsGroupEnabled}"
add a comment |
up vote
1
down vote
On your vm create a new property say
private bool _isGroupEnabled;
public bool IsGroupEnabled
{
get
{
return _isGroupEnabled;
}
set
{
_isGroupEnabled = value;
this.OnPropertyChanged("IsGroupEnabled");
}
}
Now tie into the notify process by adjusting your set
for PrintPackingCode
set
{
this.reportConfiguration.PrintPackingCode = value;
IsGroupEnabled = !value; // reverse of packing to enable/disable.
this.OnPropertyChanged("PrintPackingCode");
}
Now bind your groupbox as such:
isEnabled = "{Binding IsGroupEnabled}"
add a comment |
up vote
1
down vote
up vote
1
down vote
On your vm create a new property say
private bool _isGroupEnabled;
public bool IsGroupEnabled
{
get
{
return _isGroupEnabled;
}
set
{
_isGroupEnabled = value;
this.OnPropertyChanged("IsGroupEnabled");
}
}
Now tie into the notify process by adjusting your set
for PrintPackingCode
set
{
this.reportConfiguration.PrintPackingCode = value;
IsGroupEnabled = !value; // reverse of packing to enable/disable.
this.OnPropertyChanged("PrintPackingCode");
}
Now bind your groupbox as such:
isEnabled = "{Binding IsGroupEnabled}"
On your vm create a new property say
private bool _isGroupEnabled;
public bool IsGroupEnabled
{
get
{
return _isGroupEnabled;
}
set
{
_isGroupEnabled = value;
this.OnPropertyChanged("IsGroupEnabled");
}
}
Now tie into the notify process by adjusting your set
for PrintPackingCode
set
{
this.reportConfiguration.PrintPackingCode = value;
IsGroupEnabled = !value; // reverse of packing to enable/disable.
this.OnPropertyChanged("PrintPackingCode");
}
Now bind your groupbox as such:
isEnabled = "{Binding IsGroupEnabled}"
answered Nov 8 at 12:21
ΩmegaMan
15.7k44160
15.7k44160
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206716%2faccessing-a-component-in-a-viewmodel-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Why don't you bind GroupBox.IsEnabled to this property?
– Rob
Nov 8 at 11:48
I would, if you'd knew how it works
– Peter
Nov 8 at 12:03
Post some xaml snippets from you code and show us the code where you assign the viewModel
– Rob
Nov 8 at 12:04