BooleanToVisibilityConverter to collapse/show a TabItem












0















In MainWindow.xaml I have the following...



<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
</Window.Resources>

// Tab control

<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=DebugTabState, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


In MainWindow.xaml.cs I have the following...



public bool DebugTabState
{
get
{
return AppData.EnableDebuggingCheckBox;
}
}


In DebugSettings.xaml I have the following...



<CheckBox x:Name="EnableDebuggingCheckBox" Content="Enable Debugging" IsChecked="{Binding Path=EnableDebugging}" />


In DebugSettings.xaml.cs I have the following...



public bool EnableDebugging
{
get
{
return AppData.EnableDebuggingCheckBox;
}
set
{
AppData.EnableDebuggingCheckBox = value;
}
}


And finally, in AppData.cs I have the following...



private bool _enableDebuggingCheckBox;

public bool EnableDebuggingCheckBox
{
get
{
return _enableDebuggingCheckBox;
}
set
{
_enableDebuggingCheckBox = value;
OnPropertyChanged("EnableDebuggingCheckBox");
}
}


Checking and unchecking EnableDebuggingCheckBox updates the value to true or false, as expected, but the DebugTab isn't hiding or showing. Am I missing something?



Thanks!










share|improve this question


















  • 3





    There is no OnPropertyChanged notification from MainWindow.DebugTabState

    – Klaus Gütter
    Nov 15 '18 at 14:57











  • Somewhere you have local:DebugSettings and then an additional property in the view? Why not binding directly to that control (just give it an x:Name): Visibility="{Binding DebugTabState, ElementName=debugSettings, ...} ? I recommend you to look into MVVM earlier, it will help you to design better UI.

    – Sinatr
    Nov 15 '18 at 15:25











  • @Sinatr - The checkbox is in a usercontrol separate from MainWindow where I need to hide/show the tab. My thought was that updating a public variable that holds the last state of the checkbox and implements INotifyPropertyChanged would resolve the issue.

    – user642153
    Nov 15 '18 at 15:30











  • Sure, you can implement INotifyPropertyChanged in the class holding DebugTabState, then subscribe to PropertyChanged event of class with EnableDebuggingCheckBox to rise notification for DebugTabState, but this is silly.

    – Sinatr
    Nov 15 '18 at 15:35
















0















In MainWindow.xaml I have the following...



<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
</Window.Resources>

// Tab control

<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=DebugTabState, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


In MainWindow.xaml.cs I have the following...



public bool DebugTabState
{
get
{
return AppData.EnableDebuggingCheckBox;
}
}


In DebugSettings.xaml I have the following...



<CheckBox x:Name="EnableDebuggingCheckBox" Content="Enable Debugging" IsChecked="{Binding Path=EnableDebugging}" />


In DebugSettings.xaml.cs I have the following...



public bool EnableDebugging
{
get
{
return AppData.EnableDebuggingCheckBox;
}
set
{
AppData.EnableDebuggingCheckBox = value;
}
}


And finally, in AppData.cs I have the following...



private bool _enableDebuggingCheckBox;

public bool EnableDebuggingCheckBox
{
get
{
return _enableDebuggingCheckBox;
}
set
{
_enableDebuggingCheckBox = value;
OnPropertyChanged("EnableDebuggingCheckBox");
}
}


Checking and unchecking EnableDebuggingCheckBox updates the value to true or false, as expected, but the DebugTab isn't hiding or showing. Am I missing something?



Thanks!










share|improve this question


















  • 3





    There is no OnPropertyChanged notification from MainWindow.DebugTabState

    – Klaus Gütter
    Nov 15 '18 at 14:57











  • Somewhere you have local:DebugSettings and then an additional property in the view? Why not binding directly to that control (just give it an x:Name): Visibility="{Binding DebugTabState, ElementName=debugSettings, ...} ? I recommend you to look into MVVM earlier, it will help you to design better UI.

    – Sinatr
    Nov 15 '18 at 15:25











  • @Sinatr - The checkbox is in a usercontrol separate from MainWindow where I need to hide/show the tab. My thought was that updating a public variable that holds the last state of the checkbox and implements INotifyPropertyChanged would resolve the issue.

    – user642153
    Nov 15 '18 at 15:30











  • Sure, you can implement INotifyPropertyChanged in the class holding DebugTabState, then subscribe to PropertyChanged event of class with EnableDebuggingCheckBox to rise notification for DebugTabState, but this is silly.

    – Sinatr
    Nov 15 '18 at 15:35














0












0








0








In MainWindow.xaml I have the following...



<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
</Window.Resources>

// Tab control

<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=DebugTabState, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


In MainWindow.xaml.cs I have the following...



public bool DebugTabState
{
get
{
return AppData.EnableDebuggingCheckBox;
}
}


In DebugSettings.xaml I have the following...



<CheckBox x:Name="EnableDebuggingCheckBox" Content="Enable Debugging" IsChecked="{Binding Path=EnableDebugging}" />


In DebugSettings.xaml.cs I have the following...



public bool EnableDebugging
{
get
{
return AppData.EnableDebuggingCheckBox;
}
set
{
AppData.EnableDebuggingCheckBox = value;
}
}


And finally, in AppData.cs I have the following...



private bool _enableDebuggingCheckBox;

public bool EnableDebuggingCheckBox
{
get
{
return _enableDebuggingCheckBox;
}
set
{
_enableDebuggingCheckBox = value;
OnPropertyChanged("EnableDebuggingCheckBox");
}
}


Checking and unchecking EnableDebuggingCheckBox updates the value to true or false, as expected, but the DebugTab isn't hiding or showing. Am I missing something?



Thanks!










share|improve this question














In MainWindow.xaml I have the following...



<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
</Window.Resources>

// Tab control

<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=DebugTabState, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


In MainWindow.xaml.cs I have the following...



public bool DebugTabState
{
get
{
return AppData.EnableDebuggingCheckBox;
}
}


In DebugSettings.xaml I have the following...



<CheckBox x:Name="EnableDebuggingCheckBox" Content="Enable Debugging" IsChecked="{Binding Path=EnableDebugging}" />


In DebugSettings.xaml.cs I have the following...



public bool EnableDebugging
{
get
{
return AppData.EnableDebuggingCheckBox;
}
set
{
AppData.EnableDebuggingCheckBox = value;
}
}


And finally, in AppData.cs I have the following...



private bool _enableDebuggingCheckBox;

public bool EnableDebuggingCheckBox
{
get
{
return _enableDebuggingCheckBox;
}
set
{
_enableDebuggingCheckBox = value;
OnPropertyChanged("EnableDebuggingCheckBox");
}
}


Checking and unchecking EnableDebuggingCheckBox updates the value to true or false, as expected, but the DebugTab isn't hiding or showing. Am I missing something?



Thanks!







c# wpf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 14:55







user642153















  • 3





    There is no OnPropertyChanged notification from MainWindow.DebugTabState

    – Klaus Gütter
    Nov 15 '18 at 14:57











  • Somewhere you have local:DebugSettings and then an additional property in the view? Why not binding directly to that control (just give it an x:Name): Visibility="{Binding DebugTabState, ElementName=debugSettings, ...} ? I recommend you to look into MVVM earlier, it will help you to design better UI.

    – Sinatr
    Nov 15 '18 at 15:25











  • @Sinatr - The checkbox is in a usercontrol separate from MainWindow where I need to hide/show the tab. My thought was that updating a public variable that holds the last state of the checkbox and implements INotifyPropertyChanged would resolve the issue.

    – user642153
    Nov 15 '18 at 15:30











  • Sure, you can implement INotifyPropertyChanged in the class holding DebugTabState, then subscribe to PropertyChanged event of class with EnableDebuggingCheckBox to rise notification for DebugTabState, but this is silly.

    – Sinatr
    Nov 15 '18 at 15:35














  • 3





    There is no OnPropertyChanged notification from MainWindow.DebugTabState

    – Klaus Gütter
    Nov 15 '18 at 14:57











  • Somewhere you have local:DebugSettings and then an additional property in the view? Why not binding directly to that control (just give it an x:Name): Visibility="{Binding DebugTabState, ElementName=debugSettings, ...} ? I recommend you to look into MVVM earlier, it will help you to design better UI.

    – Sinatr
    Nov 15 '18 at 15:25











  • @Sinatr - The checkbox is in a usercontrol separate from MainWindow where I need to hide/show the tab. My thought was that updating a public variable that holds the last state of the checkbox and implements INotifyPropertyChanged would resolve the issue.

    – user642153
    Nov 15 '18 at 15:30











  • Sure, you can implement INotifyPropertyChanged in the class holding DebugTabState, then subscribe to PropertyChanged event of class with EnableDebuggingCheckBox to rise notification for DebugTabState, but this is silly.

    – Sinatr
    Nov 15 '18 at 15:35








3




3





There is no OnPropertyChanged notification from MainWindow.DebugTabState

– Klaus Gütter
Nov 15 '18 at 14:57





There is no OnPropertyChanged notification from MainWindow.DebugTabState

– Klaus Gütter
Nov 15 '18 at 14:57













Somewhere you have local:DebugSettings and then an additional property in the view? Why not binding directly to that control (just give it an x:Name): Visibility="{Binding DebugTabState, ElementName=debugSettings, ...} ? I recommend you to look into MVVM earlier, it will help you to design better UI.

– Sinatr
Nov 15 '18 at 15:25





Somewhere you have local:DebugSettings and then an additional property in the view? Why not binding directly to that control (just give it an x:Name): Visibility="{Binding DebugTabState, ElementName=debugSettings, ...} ? I recommend you to look into MVVM earlier, it will help you to design better UI.

– Sinatr
Nov 15 '18 at 15:25













@Sinatr - The checkbox is in a usercontrol separate from MainWindow where I need to hide/show the tab. My thought was that updating a public variable that holds the last state of the checkbox and implements INotifyPropertyChanged would resolve the issue.

– user642153
Nov 15 '18 at 15:30





@Sinatr - The checkbox is in a usercontrol separate from MainWindow where I need to hide/show the tab. My thought was that updating a public variable that holds the last state of the checkbox and implements INotifyPropertyChanged would resolve the issue.

– user642153
Nov 15 '18 at 15:30













Sure, you can implement INotifyPropertyChanged in the class holding DebugTabState, then subscribe to PropertyChanged event of class with EnableDebuggingCheckBox to rise notification for DebugTabState, but this is silly.

– Sinatr
Nov 15 '18 at 15:35





Sure, you can implement INotifyPropertyChanged in the class holding DebugTabState, then subscribe to PropertyChanged event of class with EnableDebuggingCheckBox to rise notification for DebugTabState, but this is silly.

– Sinatr
Nov 15 '18 at 15:35












1 Answer
1






active

oldest

votes


















0














If Appdata is a public property in MainWindow, change the binding to:



<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=AppData.EnableDebuggingCheckBox, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


You can then remove MainWindow.DebugTabState.



Alternatively, in MainWindow advise to INotifyPropertyChange from AppData and raise an PropertyChanged event if EnableDebuggingCheckBox changed






share|improve this answer
























  • I tried using AppData.EnableDebuggingCheckBox but that didn't work, and I'm not sure why. And I'm not exactly sure what you mean by the second suggestion. Thanks for your time!

    – user642153
    Nov 15 '18 at 15:28











  • You may look for binding errors using Snoop (github.com/cplotts/snoopwpf))

    – Klaus Gütter
    Nov 15 '18 at 19:28











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322155%2fbooleantovisibilityconverter-to-collapse-show-a-tabitem%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown
























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If Appdata is a public property in MainWindow, change the binding to:



<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=AppData.EnableDebuggingCheckBox, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


You can then remove MainWindow.DebugTabState.



Alternatively, in MainWindow advise to INotifyPropertyChange from AppData and raise an PropertyChanged event if EnableDebuggingCheckBox changed






share|improve this answer
























  • I tried using AppData.EnableDebuggingCheckBox but that didn't work, and I'm not sure why. And I'm not exactly sure what you mean by the second suggestion. Thanks for your time!

    – user642153
    Nov 15 '18 at 15:28











  • You may look for binding errors using Snoop (github.com/cplotts/snoopwpf))

    – Klaus Gütter
    Nov 15 '18 at 19:28
















0














If Appdata is a public property in MainWindow, change the binding to:



<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=AppData.EnableDebuggingCheckBox, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


You can then remove MainWindow.DebugTabState.



Alternatively, in MainWindow advise to INotifyPropertyChange from AppData and raise an PropertyChanged event if EnableDebuggingCheckBox changed






share|improve this answer
























  • I tried using AppData.EnableDebuggingCheckBox but that didn't work, and I'm not sure why. And I'm not exactly sure what you mean by the second suggestion. Thanks for your time!

    – user642153
    Nov 15 '18 at 15:28











  • You may look for binding errors using Snoop (github.com/cplotts/snoopwpf))

    – Klaus Gütter
    Nov 15 '18 at 19:28














0












0








0







If Appdata is a public property in MainWindow, change the binding to:



<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=AppData.EnableDebuggingCheckBox, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


You can then remove MainWindow.DebugTabState.



Alternatively, in MainWindow advise to INotifyPropertyChange from AppData and raise an PropertyChanged event if EnableDebuggingCheckBox changed






share|improve this answer













If Appdata is a public property in MainWindow, change the binding to:



<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=AppData.EnableDebuggingCheckBox, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>


You can then remove MainWindow.DebugTabState.



Alternatively, in MainWindow advise to INotifyPropertyChange from AppData and raise an PropertyChanged event if EnableDebuggingCheckBox changed







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 15:06









Klaus GütterKlaus Gütter

2,56721421




2,56721421













  • I tried using AppData.EnableDebuggingCheckBox but that didn't work, and I'm not sure why. And I'm not exactly sure what you mean by the second suggestion. Thanks for your time!

    – user642153
    Nov 15 '18 at 15:28











  • You may look for binding errors using Snoop (github.com/cplotts/snoopwpf))

    – Klaus Gütter
    Nov 15 '18 at 19:28



















  • I tried using AppData.EnableDebuggingCheckBox but that didn't work, and I'm not sure why. And I'm not exactly sure what you mean by the second suggestion. Thanks for your time!

    – user642153
    Nov 15 '18 at 15:28











  • You may look for binding errors using Snoop (github.com/cplotts/snoopwpf))

    – Klaus Gütter
    Nov 15 '18 at 19:28

















I tried using AppData.EnableDebuggingCheckBox but that didn't work, and I'm not sure why. And I'm not exactly sure what you mean by the second suggestion. Thanks for your time!

– user642153
Nov 15 '18 at 15:28





I tried using AppData.EnableDebuggingCheckBox but that didn't work, and I'm not sure why. And I'm not exactly sure what you mean by the second suggestion. Thanks for your time!

– user642153
Nov 15 '18 at 15:28













You may look for binding errors using Snoop (github.com/cplotts/snoopwpf))

– Klaus Gütter
Nov 15 '18 at 19:28





You may look for binding errors using Snoop (github.com/cplotts/snoopwpf))

– Klaus Gütter
Nov 15 '18 at 19:28




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322155%2fbooleantovisibilityconverter-to-collapse-show-a-tabitem%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python