WPF Checkbox - Clicking label does not change checked state - c#

I have a CheckBox in a TabItem Header in a WPF application. I am finding that when you click on the TabItem, it is checking the CheckBox, but not opening the TabItem. I would like only the actual CheckBox to register the click event to change the state from Checked to Unchecked or vice versa. That way, clicking on the label of the CheckBox will open the TabItem.
I've tried using an empty CheckBox that has no content and then a separate Label adjacent to it, but then the TabItem tells me that it cannot have 2 headers.
<TabItem>
<TabItem.Header>
<CheckBox Name="chkExportEnabled" Content="{x:Static resources:Global.Label_Export}" IsChecked="{Binding EnableExport}"/>
</TabItem.Header>
</TabItem>

You can just use a StackPanel with Orientation='Horizontal' around the label-less CheckBox and the Label. TabItem.Header may only contain a single child, that's why you get the error, but nothing prevents you from using layout containers as that child.

Related

How can I design a region settings like this in WPF

Till now I have a combo-box control which displays all the available region language in the UI as a combo-box items.
its in WPF and MVVM
<ComboBox
x:Name="cbLanguage"
Grid.Row="1"
Height="30"
Width="200"
HorizontalAlignment="Center"
VerticalAlignment="Top"
ItemsSource="{Binding LocalLanguages,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
SelectedIndex="0">
But I saw this window and thought this looks much more legant and modern.
Can I do similar kind of window in WPF.
I tried to change the Combobox with list-box, List-view but no result.
Any help if there is any control in WPF which can do this.
This solves many problem specially if the combo box have more than 10 items user has to scroll through the all and then select the last index. But in this way user can select any locals as all are displayed in the UI. Even user can have the option to display alphabetically.
arraging items in 3 columns can be achieved by using UniformGrid as ItemsPanel
<ComboBox.ItemsPanel>
<ItemsPanelTemplate >
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
modify ItemTemplate to change items apperance and have green color for selected item
i think it is necessary to modify ComboBox template to have custom header and footer in a dropDown (Edit Template-Edit a Copy in Visual Studio designer)
In WPF combobox is basically a Popup when the toggle button is pressed.
You could implement your own popup or you could have a look at the template of the ComboBox. Here is a link to ComboBox template

DataGrid in TabItem's ContentTemplate loses selected entry and scroll position

I've got MyDataGrid, derived from DataGrid in ContentTemplate of TabItem:
<TabControl.ContentTemplate>
<DataTemplate>
<MyDataGrid ItemsSource={Binding CurrentTab.Collection}>
...
</MyDataGrid>
</DataTemplate>
</TabControl>
(CurrentTab is current model object in my ViewModel and Collection is ObservableCollection). The issue is that when I switch tab item to another and switch back to first one, items that were selected/in view port aren't selected and DataGrid is scrolled to the start.
Also: WPF TabControl and DataGrid bugs, bugs and bugs (first "bug")
Use TemplateBinding in your Template, then pass your correspondant Tab or collection when you use it in every tab.
Check this out for more info.

Set Focusable=False cause TabItem not selectable in wpf

In a window I have some TextBoxes and a TabControl and I want only textboxes be selectable.
I set Focusable=False in TabItem. But this made TabItem not selectable. How can I fix this problem.
What I understood from your description is that you want to change focus using "Tab" key and you don't want TabControl to be selected.
For that instead of setting Focusable=false, set IsTabStop="False".
<TabItem IsTabStop="False" Header="Item 1">Content1</TabItem>
Setting IsTabStop="False" will ignore that control while changing focus using Tab key.
Hope this will solve your issue.

Silverlight RadComboBox Dropdown stays open even when not in focus

I have a user control that contains a scroll viewer. inside the scroll viewer I placed another user control with grid, and inside the grid there is a combo box.
all this is placed inside a RadWindow.
Something like this:
first user control: (displayed inside a RadWindow)
<UserControl x:class = "MyFirstUserControl">
<Grid>
<ScrollViewer>
<StackPanel x:Name="stackPanel"/>
</ScrollViewer>
</Grid>
</UserControl>
second user control:
<UserControl x:class = "MySecondUserControl">
<Grid>
<telerik:RadComboBox x:Name = "comboBox"/>
</Grid>
</UserControl>
in code behind I add the second user control to the stackPanel:
stackPanel.Children.Add(new MySecondUserControl());
Now, the problem is: when the combo-box drop down is open, and I scroll up / down the control - I expect it to close, but- it remains open...
I try to catch the MouseLeftButtonUp event of the scroll bar, and set the IsDropDownOpen of the comboBox to false, but it is false nonetheless and the drop-down still open.
How can I force the drop-down to close when focus is not on it, even if the focus is out of the combo control altogether?
Thanks,

Ucercontrol in datatemplate all objects are automaticly "shared"

So I got a tabcontrol that is bound to an list(has name and code). And this is working perfectly
<TabControl.ContentTemplate>
<DataTemplate>
<sp:ucercontroltest DataContext="{Binding}" strname="{Binding Path=name}" strcode="{Binding Path=code}" />
</DataTemplate>
</TabControl.ContentTemplate>
But if I would add a Button(btntestbutton) on usercontroltest with an event, that if the button is clicked I want the button to be disabled (btntestbutton.IsEnabled = false) then it gets disabled on ALL the usercontrols(tabs)! How can I prevent it from all being shared wich each other so If I for example want to disable the button on 1 usercontrol so that I don t automaticly disable all of them.
As far as i know TabControls reuse the controls created from the ContentTemplate, one way to have a state unique to the tabs would be to bind the IsEnabled property of the button to a property on the VM of each tab, then the state would adjust on tab-switch. (Of course you then would need to adjust the VM property in the handler, not the IsEnabled)

Categories

Resources