How to activate all the parent(i.e. one tab) of a UserControl in WPF












0















For an error validation mechanism, I've to be able to "navigate" in my application to one specific pane.



Currently I've one "SelectedNode" and tries to focus the control that is bound to this property(basically, I've an AttachedProperty to set the IsFocus, based on the name).



My issue is that sometimes this page contains tabs. And it appears that the control cannot be focused if it's hidden(not in the active tab).



Is there a way from an UserControl to go up in its visual tree to "activate" all his parent?



I cannot just bind the "SelectedIndex" of my tabcontrol in the viewModel, for a lot of reasons:




  1. The UserControl that has the tab has one sub user control for each tab, so the usercontrol doesn't know what is in which usercontrol

  2. Putting such things in the ViewModel is wrong, the ViewModel should not have to know that it's displayed in tabs or all in the same pane


Thanks!










share|improve this question























  • Maybe you could use some kind of attached behavior, which will (on "IsActive" changed event) go up on visual tree and activate each parent element?

    – vasily.sib
    Nov 16 '18 at 9:58











  • If you know how to "activate each parent element", I definitely have the structure for the rest

    – J4N
    Nov 16 '18 at 9:59











  • There is a VisualTreeHelper.GetParent() method. Take a look here

    – vasily.sib
    Nov 16 '18 at 10:03











  • @vasily.sib Ok, and how do you "activate"?

    – J4N
    Nov 16 '18 at 11:25











  • some kind of foreach (var parent in GetParents(AssociatedObject)) { if (parent is TabItem tabItem) tabItem.IsSelected = true; }

    – vasily.sib
    Nov 16 '18 at 16:27
















0















For an error validation mechanism, I've to be able to "navigate" in my application to one specific pane.



Currently I've one "SelectedNode" and tries to focus the control that is bound to this property(basically, I've an AttachedProperty to set the IsFocus, based on the name).



My issue is that sometimes this page contains tabs. And it appears that the control cannot be focused if it's hidden(not in the active tab).



Is there a way from an UserControl to go up in its visual tree to "activate" all his parent?



I cannot just bind the "SelectedIndex" of my tabcontrol in the viewModel, for a lot of reasons:




  1. The UserControl that has the tab has one sub user control for each tab, so the usercontrol doesn't know what is in which usercontrol

  2. Putting such things in the ViewModel is wrong, the ViewModel should not have to know that it's displayed in tabs or all in the same pane


Thanks!










share|improve this question























  • Maybe you could use some kind of attached behavior, which will (on "IsActive" changed event) go up on visual tree and activate each parent element?

    – vasily.sib
    Nov 16 '18 at 9:58











  • If you know how to "activate each parent element", I definitely have the structure for the rest

    – J4N
    Nov 16 '18 at 9:59











  • There is a VisualTreeHelper.GetParent() method. Take a look here

    – vasily.sib
    Nov 16 '18 at 10:03











  • @vasily.sib Ok, and how do you "activate"?

    – J4N
    Nov 16 '18 at 11:25











  • some kind of foreach (var parent in GetParents(AssociatedObject)) { if (parent is TabItem tabItem) tabItem.IsSelected = true; }

    – vasily.sib
    Nov 16 '18 at 16:27














0












0








0


1






For an error validation mechanism, I've to be able to "navigate" in my application to one specific pane.



Currently I've one "SelectedNode" and tries to focus the control that is bound to this property(basically, I've an AttachedProperty to set the IsFocus, based on the name).



My issue is that sometimes this page contains tabs. And it appears that the control cannot be focused if it's hidden(not in the active tab).



Is there a way from an UserControl to go up in its visual tree to "activate" all his parent?



I cannot just bind the "SelectedIndex" of my tabcontrol in the viewModel, for a lot of reasons:




  1. The UserControl that has the tab has one sub user control for each tab, so the usercontrol doesn't know what is in which usercontrol

  2. Putting such things in the ViewModel is wrong, the ViewModel should not have to know that it's displayed in tabs or all in the same pane


Thanks!










share|improve this question














For an error validation mechanism, I've to be able to "navigate" in my application to one specific pane.



Currently I've one "SelectedNode" and tries to focus the control that is bound to this property(basically, I've an AttachedProperty to set the IsFocus, based on the name).



My issue is that sometimes this page contains tabs. And it appears that the control cannot be focused if it's hidden(not in the active tab).



Is there a way from an UserControl to go up in its visual tree to "activate" all his parent?



I cannot just bind the "SelectedIndex" of my tabcontrol in the viewModel, for a lot of reasons:




  1. The UserControl that has the tab has one sub user control for each tab, so the usercontrol doesn't know what is in which usercontrol

  2. Putting such things in the ViewModel is wrong, the ViewModel should not have to know that it's displayed in tabs or all in the same pane


Thanks!







c# wpf xaml tabcontrol






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 9:50









J4NJ4N

6,16025114209




6,16025114209













  • Maybe you could use some kind of attached behavior, which will (on "IsActive" changed event) go up on visual tree and activate each parent element?

    – vasily.sib
    Nov 16 '18 at 9:58











  • If you know how to "activate each parent element", I definitely have the structure for the rest

    – J4N
    Nov 16 '18 at 9:59











  • There is a VisualTreeHelper.GetParent() method. Take a look here

    – vasily.sib
    Nov 16 '18 at 10:03











  • @vasily.sib Ok, and how do you "activate"?

    – J4N
    Nov 16 '18 at 11:25











  • some kind of foreach (var parent in GetParents(AssociatedObject)) { if (parent is TabItem tabItem) tabItem.IsSelected = true; }

    – vasily.sib
    Nov 16 '18 at 16:27



















  • Maybe you could use some kind of attached behavior, which will (on "IsActive" changed event) go up on visual tree and activate each parent element?

    – vasily.sib
    Nov 16 '18 at 9:58











  • If you know how to "activate each parent element", I definitely have the structure for the rest

    – J4N
    Nov 16 '18 at 9:59











  • There is a VisualTreeHelper.GetParent() method. Take a look here

    – vasily.sib
    Nov 16 '18 at 10:03











  • @vasily.sib Ok, and how do you "activate"?

    – J4N
    Nov 16 '18 at 11:25











  • some kind of foreach (var parent in GetParents(AssociatedObject)) { if (parent is TabItem tabItem) tabItem.IsSelected = true; }

    – vasily.sib
    Nov 16 '18 at 16:27

















Maybe you could use some kind of attached behavior, which will (on "IsActive" changed event) go up on visual tree and activate each parent element?

– vasily.sib
Nov 16 '18 at 9:58





Maybe you could use some kind of attached behavior, which will (on "IsActive" changed event) go up on visual tree and activate each parent element?

– vasily.sib
Nov 16 '18 at 9:58













If you know how to "activate each parent element", I definitely have the structure for the rest

– J4N
Nov 16 '18 at 9:59





If you know how to "activate each parent element", I definitely have the structure for the rest

– J4N
Nov 16 '18 at 9:59













There is a VisualTreeHelper.GetParent() method. Take a look here

– vasily.sib
Nov 16 '18 at 10:03





There is a VisualTreeHelper.GetParent() method. Take a look here

– vasily.sib
Nov 16 '18 at 10:03













@vasily.sib Ok, and how do you "activate"?

– J4N
Nov 16 '18 at 11:25





@vasily.sib Ok, and how do you "activate"?

– J4N
Nov 16 '18 at 11:25













some kind of foreach (var parent in GetParents(AssociatedObject)) { if (parent is TabItem tabItem) tabItem.IsSelected = true; }

– vasily.sib
Nov 16 '18 at 16:27





some kind of foreach (var parent in GetParents(AssociatedObject)) { if (parent is TabItem tabItem) tabItem.IsSelected = true; }

– vasily.sib
Nov 16 '18 at 16:27












0






active

oldest

votes












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%2f53335265%2fhow-to-activate-all-the-parenti-e-one-tab-of-a-usercontrol-in-wpf%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53335265%2fhow-to-activate-all-the-parenti-e-one-tab-of-a-usercontrol-in-wpf%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

Bressuire

Vorschmack

Quarantine