Can we place a devexpress ComboBoxEdit control in Bar? - wpf

I am looking for some approach that can allow me to put a devexpress ComboBoxEdit control in the Bar.
For example:
<dxb:BarManager x:Name="barManager" CreateStandardLayout="False" Grid.Row="1" Grid.Column="0">
<dxb:BarManager.Items>
<dxb:BarStaticItem Name="lblState" Content="State"/>
<dxb:BarLinkContainerItem Name="cmbStates" >
<dxb:BarLinkContainerItem.Content>
<dxb:ComboBoxEdit DisplayMember="Description" ValueMember="Id" EditValue="{Binding Filter.EquipmentId, Mode=TwoWay}" ItemsSource="{Binding Path=OrderStates, Mode=TwoWay}">
</dxb:ComboBoxEdit>
</dxb:BarLinkContainerItem.Content>
</dxb:BarLinkContainerItem>
</dxb:BarManager.Items>
<dxb:BarManager.Bars>
<dxb:Bar x:Name="Bar" Caption="Bar" UseWholeRow="True">
<dxb:Bar.DockInfo>
<dxb:BarDockInfo ContainerName="Top"/>
</dxb:Bar.DockInfo>
<dxb:Bar.ItemLinks>
<dxb:BarStaticItemLink BarItemName="lblState" />
<dxb:BarLinkContainerItemLink BarItemName="cmbStates" />
</dxb:Bar.ItemLinks>
</dxb:Bar>
</dxb:BarManager.Bars>
</dxb:BarManager>
Doing so results in the following error:
UIElement can't be set as content for a BarItemLink.
Is it possible to achieve this? What are the options to do this?

Please use the following markup:
<dxb:BarEditItem x:Name="barEditItemComboBox" EditValue="{...}">
<dxb:BarEditItem.EditSettings>
<dxe:ComboBoxEditSettings
ItemsSource="{...}"
DisplayMember="{...}"
ValueMember="{...}"
/>
</dxb:BarEditItem.EditSettings>
</dxb:BarEditItem>
Also I suggest you review the following articles:
Items and Links
The List of Bar Items and Links
ComboBoxEdit

Related

How to use a RibbonGallery with a RibbonComboBox

So I wanted to add a RibbonCombobox to my Ribbon in WPF. For some reason, RibbonCombobox does not have a selectionchanged event. I read that you should use a RibbonGallery for selection change event so I implemented this
<RibbonComboBox Label="Equations" x:Name="EquationListComboToolbar" ItemsSource="{Binding}">
<RibbonGallery x:Name="EquationListComboboxGallery" SelectedValue="{Binding XPath=.}" />
</RibbonComboBox>
Behind the scene the binding is done like this.
EquationListComboToolbar.DataContext = ViewModel.EquationNames;
this.Bind(ViewModel, vm => vm.SelectedEquation, v => v.EquationListComboboxGallery.SelectedItem).DisposeWith(cleanup);
Observable.FromEventPattern(EquationListComboboxGallery, nameof(EquationListComboboxGallery.SelectionChanged)).Subscribe(e => ViewModel.SelectEquation(EquationListComboboxGallery.SelectedItem?.ToString()));
At runtime I get the following error
"An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll
Items collection must be empty before using ItemsSource." When the app initalizez. I know it's something about the Gallery but I can't figure out what is the problem and how can I achieve this.
As I was suggested, I already tried the answer that was suggested
<RibbonComboBox Label="Equations" x:Name="EquationListComboToolbar" ItemsSource="{Binding}">
<RibbonComboBox.ItemTemplate>
<DataTemplate>
<RibbonGallery x:Name="EquationListComboboxGallery" SelectedValue="{Binding XPath=.}" />
</DataTemplate>
</RibbonComboBox.ItemTemplate>
</RibbonComboBox>
Doing this, will make by binding imposible
Ah, yes. The Microsoft ribbon library is lots of fun. Luckily I've been down this road before. Here's a working example of a RibbonComboBox from one of my applications, complete with RibbonGallery:
<RibbonComboBox DropDownHeight="400">
<RibbonGallery MaxColumnCount="1" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectedItem="{Binding MySelectedItemProperty}">
<RibbonGalleryCategory ItemsSource="{Binding MyItemsSourceProperty}"/>
</RibbonGallery>
</RibbonComboBox>
I'm not entirely sure this is the only way to do things, but I know this way works. Note that I set ItemsSource on the RibbonGalleryCategory, not the RibbonComboBox itself. It might be possible to use the RibbonGallery without a RibbonGalleryCategory, in which case you would set ItemsSource on RibbonGallery, but I've not tested this.
Note you also have the ability to add multiple galleries categories to a single RibbonComboBox like so:
<RibbonComboBox DropDownHeight="400">
<RibbonGallery MaxColumnCount="1" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectedItem="{Binding MySelectedItemProperty}">
<RibbonGalleryCategory ItemsSource="{Binding MyFirstItemsSourceProperty}"/>
<Separator/>
<RibbonGalleryCategory ItemsSource="{Binding MySecondItemsSourceProperty}"/>
</RibbonGallery>
</RibbonComboBox>
The above lets you show multiple lists in the same drop down and allows the user to select a single item from any list. Functionality like this is probably why RibbonGalleryCategory exists in the first place.

Bind to selected rows in GridControl

I would like to get a list of the objects selected in GridControl (DevExpress)
Would you know how I could do so?
<dxg:GridControl ItemsSource="{Binding Cars}">
Found the way to do this.
Way 1
If having DevExpress 15.5 (which I don't), simply use the SelectedItem property: https://documentation.devexpress.com/#WPF/DevExpressXpfGridDataControlBase_SelectedItemstopic
Way 2
Create a behavior to hook the TableView inside the GridControl if you have:
<dxg:GridControl ItemsSource="{Binding Cars}">
<dxg:GridControl.View>
<Controls:TableView >
<i:Interaction.Behaviors>
<view:CollectionObserverBehavior SelectedItems="{Binding SelectedCars}" />
</i:Interaction.Behaviors>
</Controls:TableView>
Behavior details in the good article here: http://social.technet.microsoft.com/wiki/contents/articles/22871.wpfmvvm-binding-to-read-only-properties-using-behaviors.aspx

Why ItemTemplate will make items disappear for ListView?

I was solving Windows Phone 8.1 ListView wobbling problem and had code like below, however, once I add the ItemTemplate, the contents of the List cannot be seen, I'm wondering why and how to fix the problem.
<ListView
Grid.Row="1"
x:Name="ListViewEvents"
Loaded="OnListViewEventsLoaded"
ItemsSource="{Binding xx}"
ItemTemplateSelector="{StaticResource xx}"
ItemContainerStyle="{StaticResource xx}"
IsItemClickEnabled="True">
<ListView.ItemTemplate >
<DataTemplate >
<Grid Width="{Binding ActualWidth, ElementName=EventsListGrid}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Your Width binding is trying to read the ActualWidth property of an element in your XAML named EventsListGrid, but there's no such element in the sample code you've provided. As such, the binding engine is unable to set the Width property on your grid, most likely setting it to some unset/NaN value. At least I can confirm this when setting up a similar case as the one you provided and inspecting in Snoop the ListViewItem containers generated for each item in the test collection bound to the ListView. Perhaps you want to set the element name to ListViewEvents in this case or some other parent element not shown in the example?

DataBinding to a List in silverlight

I've got a Grid which contains a TextBlock. The Grid's DataContext is of type List<MyClass>, and I'd like to bind the TextBlock.Text property to the MyClass.MyProperty property of first element in the List. I tried something like:
<Grid x:Name="RootLayout">
<TextBlock Text="{Binding [0].MyProperty}" />
</Grid>
But of course, that did not work. What's the right way of doing this?
Edit:
I'm going to try and make my explanation more clear. I've got multiple elements in the grid, each of which binds to a different item in the list. The items are laid out in a customized manner which cannot be accomplished by a GridView or ListBox. One of the items in the Grid is the TextBlock, and I'd like to bind its Text property to a property of the first element in the list. Once I know how to do that, I can extend that knowledge to add bindings to the rest of the elements in the grid.
Edit 2:
Turns out, my code works just fine in Silverlight. My project is actually a WinRT project, but I figured I'd get quicker answers if I tagged it as Silverlight, since databinding is supposed to work the same. I'm assuming this is a bug in WinRT, so I'll just have to find a workaround for it :(
I'm not sure I get why you want to do this, but you could create a property that returns what you want from the item in the list like so:
public string MyBindingProperty
{
get { return MyList != null && MyList.Count > 0 ? MyList[0].MyProperty : "Error Text"; }
}
Then you'd bind to MyBindingProperty:
<TextBlock Text="{Binding MyBindingProperty}" />
EDIT
I was wrong in saying you can't get at the items in the List - my bad. Your binding should look like this:
<TextBlock Text="{Binding [0].MyProperty}" />
If you need me I'll be in the corner enjoying my humble pie.
I am not an expert of SL but I think your are using the wrong Grid object; try with DataGrid in this way:
<data:DataGrid x:Name="targetDataGrid">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="MyProperty"
Binding="{Binding MyProperty}" />
</data:DataGrid.Columns>
</data:DataGrid>
also see here for more details: Defining Silverlight DataGrid Columns at Runtime
Edit: then go this way:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding MyProperty}" />
</Grid>
found here: http://msdn.microsoft.com/en-us/library/cc278072%28v=VS.95%29.aspx scroll donw the article...

Dialog form in wpf change content

I want to display a dialog form for new and edit actions... However title, buttons , and few other things should change.
I am wondering how i could implement this. Provide an enum value at constructor ? Like Mode.New or Mode.Edit ? Is there a way to avoid writing code like spNewButtons.Visibillity=Collapsed .. etc , and put it inside wpf ?
You can bind visibility with your mode property, and create a specific IValueConverter to convert the mode to a proper Visibility value. ie:
<StakPanel Visibility={Binding Mode,Converter={StaticResource myProperConverter}}></StackPanel>
Usually my WPF dialogs are all ContentControls that get displayed in a Popup.
My code usually looks like this:
<Grid Name="RootPanel">
<!-- Other Content -->
<!-- Popup is always last so it gets displayed on top of other contnet -->
<local:PopupPanel
local:PopupPanel.PopupParent="{Binding ElementName=RootPanel}"
local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}"
local:PopupPanel.PopupEnterKeyCommand="{Binding SaveCommand}"
local:PopupPanel.PopupEscapeKeyCommand="{Binding CancelCommand}">
<DockPanel>
<!-- Header -->
<Label DockPanel.Dock="Top" Content="{Binding PopupHeader}" />
<!-- Buttons -->
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Save" Command="{Binding PopupSaveCommand}" />
<Button Content="Cancel" Command="{Binding PopupCancelCommand}" />
</StackPanel>
<!-- Actual content displayed is determined by DataTemplates -->
<ContentControl Content="{Binding PopupContent}" />
</DockPanel>
</local:PopupPanel>
</Grid>
I removed a lot of the styles to make this easier to read, but you can see the general idea of how it's put together. My ViewModel usually contains properties for IsPopupVisible, PopupContent, and PopupHeader, and commands for PopupSaveCommand and PopupCancelCommand
I use my own custom popup in most cases, although the same thing could be done with a WPF popup.

Resources