For a label, I have a list of items to show on context menu and can select many items.
Can it be a checkbox for each item on context menu?
Below is my current xaml codes:
<Label Content="{Binding Count}">
<Label.ContextMenu>
<ContextMenu ItemsSource="{Binding Items}" >
<ContextMenu.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
</Label.ContextMenu>
</Label>
additional question: about remove the empty gap infront of the checkbox, I have used #Rohit reply already but it still has a line behind the checkbox item. Can it be delete?
Yeah you can have checkBox. Simply replace TextBlock with CheckBox.
<ContextMenu ItemsSource="{Binding Items}" >
<ContextMenu.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Name}" />
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
Update for comment
how to remove an empty gap infront of the checkbox?
First please refrain from asking follow up questions in comments since it's not visible to larger audience here.
Now for your question - That's default template of ContextMenu which is getting applied. To avoid that you to override Template of ContextMenu. Refer to the template from here in case interested (modify it as per your needs)
However, there is quick and dirty way to achieve that by specifying negative left margin:
<CheckBox Margin="-35,0,0,0" Content="{Binding Name}" />
Related
I'm trying to swap out a WPF datagrid to a xceed\Extended WPF Toolkit DataGridControl.
I need to react to the click event in a checkbox column ... to summarizing a number of other columns.
In the existing datagrid I have a checkbox column, that is bound to a Observable Collection and I call a method if any check box is checked\unchecked. The xaml I use for this, which works, is as such:
<DataGridTemplateColumn Width="40" Header="Inc">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox
IsChecked="{Binding Include ,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Checked="CheckBoxUpdated" Unchecked="CheckBoxUpdated" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
For the xceed datagridcontrol I started with the simple syntax below, and the the initial binding seemed OK, but I don't have a click event to respond to:
<xcdg:Column FieldName="Include" Title="Inc" />
Now I tried to do something similar to the original code using the xceed datagridcontrol, as such:
<xcdg:Column FieldName="Include" Title="Inc" Width="*" >
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Include ,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="CheckBoxUpdated"/>
</DataTemplate>
</xcdg:Column.CellContentTemplate>
But I don't think this is the correct syntax. It seems the binding is not working ... based on the initial values of the collection.
(note code behind sets this items source as such dg.ItemsSource = collectionView;)
Any ideas on how to setup a checkbox DataTemplate and the binding correctly?
Thanks
I just found a post at xceed forums that gave me the syntax I needed, that to set the FieldName=".", not FieldName="Include" . My guess is that having FieldName="Include" and the "{Binding Include ..." was confusing the binding.
<xcdg:Column FieldName="." Title="Inc" Width="*" >
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Include ,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Click="CheckBoxUpdated"/>
</DataTemplate>
</xcdg:Column.CellContentTemplate>
Your solution to your question wasn't working for me, what did work however:
Either
<xcdg:Column ...
if the type is boolean it will automaticly create a checkbox for it, you'll have to click 3 times though (column edit -> (un)check -> column out) which can be annoying.
OR
<xcdg:Column FieldName="ckb1" DisplayMemberBinding="{Binding Path=IsThisChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" >
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<CheckBox IsChecked="{xcdg:CellEditorBinding NotifyOnSourceUpdated=True}" HorizontalAlignment="Center" />
</DataTemplate>
</xcdg:Column.CellContentTemplate>
</xcdg:Column>
Which doesn't need all the clicking
I have a multiselect combobox that works fine. Except for the text. I want it to always have the same text ("Commodity Filter") regardless of what the user has selected.
If I set iseditable to true and the text to CommodityFilter it looks fine until the user makes a selection, then it is garbage (displays object type name). How can I hard code some text there? (Actually ideally i would databind it so it can change depending on whether anything is selected, but that would be a bonus at this point)
<ComboBox IsEditable="True" Text ="Commodity Filter" ItemsSource="{Binding Path=ActiveCommodities}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected}"
Width="20" />
<TextBlock Text="{Binding Commodity}"
Width="100" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
I ended up creating a custom object for populating the ComboBox (which had the IsSelected property and implemented INotifyPropertyChanged) because I was creating several comboboxes to control filtering. Once I did this is was trivial to override the tostring on the customobject and pass in the appropriate text. So the xaml did not change much.
I would have preferred to overlay with a text box but that seemed to be beyond my abilities to get a polished look in a reasonable time.
<ComboBox ItemsSource="{Binding Path=ActiveFuturesMonths}"
IsEditable="True"
IsReadOnly="True"
Text="Futures Month Filter" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected}"
Width="20" />
<TextBlock Text="{Binding Text}"
Width="100" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Actually the crux is in setting -
IsEditable="True"
IsReadOnly="True"
Text="Futures Month Filter"
rather than creating custom object. thanks a lot it helped.
I have a form:
<StackPanel Orientation="Horizontal" Visibility="{Binding Editable, Converter={StaticResource visibilityConverter}}"
ToolTipService.ToolTip="Add new topic to this group">
<sdk:AutoCompleteBox Width="160" ItemsSource="{Binding ElementName=LayoutRoot, Path=DataContext.TopicNames}" />
<Button Click="addTopicButton_Click">
<Image Source="Images/appbar.add.rest.png" />
</Button>
</StackPanel>
This form appears in a DataTemplate for an ItemsControl. I'm not sure what the best way is to get the data from the AutoCompleteBox when the button is clicked. I can't give the elements x:Name attributes, because they're in a template (right?).
How can I get around this? The Click event will give me the Button, but I need a reference to the text box. Use the Button's parent, then look through the children for the Textbox? If I factored this out into its own UserControl, I could set x:Name values, but I'd rather not do that.
Any other ideas?
Update: Here is another example of such a problem:
<ListBox x:Name="topicList"
ItemsSource="{Binding Id, Converter={StaticResource topicGroupIDConverter}}"
SelectionChanged="ListBox_SelectionChanged"
HorizontalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}"
Width="150"
VerticalAlignment="Center"
ToolTipService.ToolTip="{Binding Description}"
ToolTipService.Placement="Right" />
<Button ToolTipService.ToolTip="Remove this topic from this group"
Visibility="{Binding ElementName=topicList,
Path=DataContext.Editable,
Converter={StaticResource visibilityConverter}}"
Click="removeTopicButton_Click"
HorizontalAlignment="Right"
Margin="10,0">
<Image Source="Images/appbar.cancel.rest.png" />
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
When the button is clicked, I want to access topicList.DataContext. However, topicList itself is a DataTemplate in an ItemsControl, so I can't access it using its name from code-behind. How else can I do this?
You can add a property, say SelectedItemInAutoCompleteBox, to your presenter, and then can bind it to the SelectedItem property of AutoCompleteBox, using Mode=TwoWay, like this,
<sdk:AutoCompleteBox SelectedItem="{Binding Path=DataContext.SelectedItemInAutoCompleteBox, Mode=TwoWay}" ... />
You may try the same approach with Text property of AutoCompleteBox, also. See if it solves your problem.:-)
You have several choices:
If you're on Silverlight 5, use the AncestorBinding
Otherwise, use a Silverlight 4 AncestorBinding hack (it doesn't look pretty)
Or you could try DataContextProxy, which stores the DataContext in a resource so that it is accessible. Note: you should set the DataContextProxy as a Resource of topicList ListBox, not the UserControl as in Dan Wahlin's example.
I have and object model, a UserProfile, that contains many ServiceProfile, each containing many CommandProfile.
I have bound this model with Telerik WPF OutlookBar:
<telerikNavigation:RadOutlookBar
ItemsSource="{Binding ServiceProfiles}"
Background="{Binding Color}">
<telerikNavigation:RadOutlookBar.TitleTemplate>
<DataTemplate>
<Label Content="{Binding Description}"/>
</DataTemplate>
</telerikNavigation:RadOutlookBar.TitleTemplate>
<telerikNavigation:RadOutlookBar.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Description}"/>
</DataTemplate>
</telerikNavigation:RadOutlookBar.ItemTemplate>
<telerikNavigation:RadOutlookBar.ContentTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding CommandProfiles}" Background="Transparent">
<ListBox.ItemTemplate>
<DataTemplate>
<Button
Content="{Binding Description}"
Command="{Binding ExecuteCommand}"
/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</telerikNavigation:RadOutlookBar.ContentTemplate>
</telerikNavigation:RadOutlookBar>
This XAML code creates a OutlookbarItem for each ServiceProfile. Each OutlookbarItem presents a list of buttons as a content.
I'm not able to do the analogous job with ribbonBar: inside a single tab (referring to my UserProfile), I want to create a RibbonGroup for each ServiceProfile. Inside each Group (Service profile) there are many Ribbonbuttons, one for each CommandProfile.
But I'm not able.
I arrive to this code:
<telerikRibbonBar:RadRibbonTab
x:Name="theTab"
Header="{Binding Description}"
Background="{Binding Color}"
ItemsSource="{Binding ServiceProfiles}">
</telerikRibbonBar:RadRibbonTab>
which creates the ribbongroups, but I'm not able to control anything (title of the group, fill (via Binding) the content.
Any idea?
Thanks
Marco Parenzan
Bit late, but sorry to say but it doesn't look supported yet:
http://www.telerik.com/community/forums/silverlight/ribbonbar/headertemplate-of-radribbontab.aspx
Hello Alex Fan,
Unfortunately the RibbonBar doesn't support databinding for now. However, you can put your vote for this feature in our PITS thus increasing its priority.
In your case the best will be if you add the ribbon items programmatically.
Let us know if you need more info.
All the best,
Tina Stancheva
the Telerik team
Can you surround Datafields in a border? I have a large form that needs to be organized into sections, "Customer INformation" for instance.
Is there a way to surround these with a border?
I kinda get the feeling you are not specifying your own edit template for the control but a letting data form do it for you. I get this feeling because if you are already using an edit template you wouldn't be asking the question. Consider this:-
<dataform:DataForm x:Name="dataForm">
<dataform:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<Border BorderBrush="Black" BorderThickness="2">
<StackPanel>
<dataform:DataField>
<TextBox Text="{Binding ID, Mode=TwoWay}" />
</dataform:DataField>
<dataform:DataField>
<TextBox Text="{Binding Name, Mode=TwoWay}" />
</dataform:DataField>
</StackPanel>
</Border>
<dataform:DataField>
<CheckBox IsChecked="{Binding Test, Mode=TwoWay}" />
</dataform:DataField>
</StackPanel>
</DataTemplate>
</dataform:DataForm.EditTemplate>
</dataform:DataForm>
Adding a border around the ID and Name fields is a simple case of placing them in their own StackPanel and putting that in a Border. Basically with a template you can do anything you want with the form appearance, in fact you don't even need the DataField if you feel you can do a better job with label placement etc in your own XAML.