Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:05:22+00:00 2026-05-25T20:05:22+00:00

I’m rewrite default template of ListBoxItems & ListBox. Here MainWindow.xaml <Window x:Class=NestedBindingTry.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml

  • 0

I’m rewrite default template of ListBoxItems & ListBox. Here MainWindow.xaml

<Window x:Class="NestedBindingTry.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Loaded="Window_Loaded"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Grid.Resources>
        <Style TargetType="ListBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                                <StackPanel 
                                            IsItemsHost="True"
                                            FocusManager.IsFocusScope="False"
                                            />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Grid.Resources>
    <StackPanel FocusManager.IsFocusScope="True"
                KeyboardNavigation.ControlTabNavigation="Cycle"
                KeyboardNavigation.DirectionalNavigation="Cycle">
        <StackPanel>
            <CheckBox Content="SelectAll" />
        </StackPanel>
        <ListBox SelectionMode="Multiple" Name="M" ItemsSource="{Binding}" FocusManager.IsFocusScope="False">
            <ListBox.Resources>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <Grid>
                                    <VisualStateManager.VisualStateGroups>                                        
                                        <VisualStateGroup x:Name="SelectionStates">
                                            <VisualState x:Name="Unselected">
                                                <Storyboard>
                                                    <BooleanAnimationUsingKeyFrames Storyboard.TargetName="CheckBox"
                                                                                    Storyboard.TargetProperty="IsChecked">
                                                        <DiscreteBooleanKeyFrame KeyTime="0"
                                                                                 Value="False" />
                                                    </BooleanAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="Selected">
                                                <Storyboard>
                                                    <BooleanAnimationUsingKeyFrames Storyboard.TargetName="CheckBox"
                                                                                    Storyboard.TargetProperty="IsChecked">                                                    
                                                        <DiscreteBooleanKeyFrame KeyTime="0"
                                                                                 Value="True" />
                                                    </BooleanAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="SelectedUnfocused">
                                                <Storyboard>
                                                    <BooleanAnimationUsingKeyFrames Storyboard.TargetName="CheckBox"
                                                                                    Storyboard.TargetProperty="IsChecked">
                                                        <DiscreteBooleanKeyFrame KeyTime="0"
                                                                                 Value="True" />
                                                    </BooleanAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                    <CheckBox Focusable="False"
                                              Name="CheckBox"
                                              Content="{Binding}"
                                              Checked="CheckBox_Checked"
                                              Unchecked="CheckBox_Unchecked"
                                              VerticalAlignment="Center" 
                                              Margin="0,0,3,0" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.Resources>
        </ListBox>
    </StackPanel>
</Grid>
</Window>

Here codeBehind MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NestedBindingTry
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = new List<string>() { "123", "546", "789"};
    }

    private void CheckBox_Checked(object sender, RoutedEventArgs e)
    {
        CheckBox bik = sender as CheckBox;
        DependencyObject dob = bik as DependencyObject;
        while (dob.GetType() != typeof(ListBox))
        {
            dob = VisualTreeHelper.GetParent(dob);
        }
        ListBox my = dob as ListBox;
        if (!my.SelectedItems.Contains(bik.DataContext))
            my.SelectedItems.Add(bik.DataContext);
    }

    private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
    {
        CheckBox bik = sender as CheckBox;
        DependencyObject dob = bik as DependencyObject;
        while (dob.GetType() != typeof(ListBox))
        {
            dob = VisualTreeHelper.GetParent(dob);
        }
        ListBox my = dob as ListBox;
        if (my.SelectedItems.Contains(bik.DataContext))
            my.SelectedItems.Remove(bik.DataContext);
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        this.M.SelectedItems.Add(((IList<string>)this.DataContext)[0]);
        this.M.SelectedItems.Add(((IList<string>)this.DataContext)[2]);
    }
}
}

Main idea I want to achive – is to create checkable ListBox. One feature I want to have – is Select All CheckBox. But here the problem. SelectAll CheckBox is not laying inside ListBox. So its under it.

I want that focus worked like SelectAll CheckBox lay inside ListBox. It means, that when I click Tab key, focus should go to the next CheckBox. In my case, if ListBox have more than 1 item, its just change focus between two CheckBoxes – between SelectAll CheckBox and first from ListBox item. But I want it goes down to the next ListBox item. I try to play with FocusManager's properties, but nothing happens.
Any suggestion…?

Bad focus example

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:05:22+00:00Added an answer on May 25, 2026 at 8:05 pm

    Use ItemsControl instead of ListBox…. the ListBox hails from Selector base class and this class somehow overrides simple Tab based focus for its items with Control + Up / Down Arrow in its ItemsPanel.

    When I used ItemsControl it worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.