|
Should work as long as your are binding to a <b>UIElement</b> that has its DataContext set properly. We already the top level window has its DataContext set to your VM, so you must point your ComboBox's DataContext to the VM if you want to reference properties from the VM.
You might to post your full XAML and what error messages you are getting. Also, try turning on verbose WPF debugging.
|
|
|
|
|
Here's the XAML as it is now:
<DataGrid x:Name="grdItems"
Grid.Row="4"
Grid.Column="0"
Grid.ColumnSpan="2"
AutoGenerateColumns="False"
ItemsSource="{Binding SearchItems}"
Visibility="{Binding GridVisible, Converter={StaticResource visibilityConverter}}"
Margin="5">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Search Terms"
Width="*">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox x:Name="cboBOMs"
Height="22"
DataContext="{Binding ElementName=QueryView, Path=DataContext}"
IsEditable="True"
ItemsSource="{Binding BOMs}"
SelectedItem="{Binding SelectedBOMItem}"></ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Quantity"
Binding="{Binding Quantity}"
Width="100">
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
I don't understand what's going on because this code is in QueryView.xaml. You can see the combo is looking for the DC on QueryView.
The output window shows the error:
Cannot find source for binding with reference 'ElementName=QueryView'. BindingExpression:Path=DataContext; DataItem=null; target element is 'ComboBox' (Name='cboBOMs'); target property is 'DataContext' (type 'Object')
This appeaars to be right. I don't get it and I'm tired of screwing with it. if the DB wasn't so damn big I'd post the entire app on my site and ask for more help. I'm fairly frustrated at this point.
Everything makes sense in someone's mind
|
|
|
|
|
How about using grdItems for ElementName? What type is QueryView? Seems like this should be working to me too.
|
|
|
|
|
Within a DataGrid, you need to use a DataGridComboBoxColumn in your template.
Here[^] is some code that might help you out.
|
|
|
|
|
Hi All,
I have a parent grid in one xaml file in which we are loading the different regions. For that grid the column definitions are defined in the following way
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10" />
<ColumnDefinition MinWidth="744" Width="*" />
<ColumnDefinition Width="10" />
</Grid.ColumnDefinitions> in the second column we are loading a different user control, is there any way to get the MinWidth=744 value in the child user control dynamically through code.
I want to get that value what we set here in the user control which will be loaded in that second column. I have hard coded it but I want to use it in the following way in a different user control (means different xaml file)
if (assignmentOperator.ActualWidth > 744)
{
double temp = gridFilterCriteria.ActualWidth;
this.textBlockCriteria.Width = temp * (0.99);
}
here instead of 744 I want to set this if condition dynamically like
if (assignmentOperator.ActualWidth > <here i="" want="" some="" property="" which="" would="" give="" me="" this="" value="">)
can anybody help me please, I need it friends. Please help me yaar.
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
You can loop over the set of grids in your xaml, get the appropriate control (access the children and get the column name) and then set its MinWidth value to what you need. This is not the neatest way to do this, but will get the width set.
|
|
|
|
|
Here's the code
private void login()
{
Login loginView = new Login();
loginView.ShowDialog();
if (MyAppEngine.CurrentUser == null)
{
Application.Current.Shutdown();
}
}
The app is crashing with a null object ref exception on the Shutdown line when I fail to log in. Why would Application.Current ever be null??
Everything makes sense in someone's mind
|
|
|
|
|
Probably calling this method too early??
|
|
|
|
|
But during runtime you would thnk that Application.Current would exist.
Everything makes sense in someone's mind
|
|
|
|
|
As I said, depends from where. If you are calling your method really early on (say in the app constructor, or a main() override, the start up code that inits that property hasn't executed yet.
|
|
|
|
|
I assume that you are running this prior to the initialisation of the application pump. If you take control of starting your application (i.e. you don't just rely on StartupUri), you need to be aware of when your application actually "starts". I'd say that your logic would be better expressed as:
if (login())
{
}
|
|
|
|
|
as captioned.
Is there an existing control to pick a color just like the datepicker ? I can not find it in the MSDN library ....
|
|
|
|
|
No but there's lots of example source code floating around...
Mark Salsbery
|
|
|
|
|
Our very own Sacha Barber has implemented just such a thing[^]. Enjoy.
|
|
|
|
|
|
I keep getting this error. I kind of new to wpf and not sure what the issue is.
Here is my code:
<DataGrid AutoGenerateColumns="False" Height="770" Name="DataGrid1" Width="1506" ItemsSource="{Binding}">
<Style TargetType="{x:Type DataGridRow}" >
<Style.Triggers>
<DataTrigger Binding="{Binding Alert_Level}" Value="1">
<Setter Property="Background" Value="LightYellow" />
</DataTrigger>
</Style.Triggers>
</Style>
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding TicketID}" IsReadOnly="True" Width="70" FontSize="24" />
<DataGridTextColumn Header="Date" Binding="{Binding Date_Entered}" IsReadOnly="True" Width="100" FontSize="24" />
<DataGridTextColumn Header="Input By" Binding="{Binding Requestor}" IsReadOnly="True" Width="200" FontSize="24"/>
<DataGridTextColumn Header="Telephone" Binding="{Binding Requestor_telep}" IsReadOnly="True" Width="120" FontSize="24"/>
<DataGridTextColumn Header="Status" Binding="{Binding Status}" IsReadOnly="True" Width="120" FontSize="24"/>
<DataGridTextColumn Header="Alert" Binding="{Binding Alert_Level}" IsReadOnly="True" Width="40" FontSize="24"/>
<DataGridTextColumn Header="Assigned" Binding="{Binding Assigned_To}" IsReadOnly="True" Width="200" FontSize="24"/>
<DataGridTextColumn Header="Issue" Binding="{Binding Problem_detail}" IsReadOnly="True" Width="300*" FontSize="24"/>
</DataGrid.Columns>
</DataGrid>
Thanks
|
|
|
|
|
I would guess based on what you've shown, the Style ends up being just a datagrid item (an object representing a datagrid row). That style should be in the resources somewhere, for example
<DataGrid ...>
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridRow}" >
<Style.Triggers>
<DataTrigger Binding="{Binding Alert_Level}" Value="1">
<Setter Property="Background" Value="LightYellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
...
</DataGrid.Columns>
<DataGrid>
Mark Salsbery
|
|
|
|
|
Thanks mark,
That took care of my error. I still can not get the background to show a color base on a value. But that is a complete separate issue. Thanks for your help
|
|
|
|
|
jhoga wrote: I still can not get the background to show a color base on a value.
Maybe the resource needs to be at least one level up the tree from the datagrid.
Regardless, perhaps try using ItemContainerStyle instead, something like this
<DataGrid ...>
<DataGrid.ItemContainerStyle>
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource {x:Type DataGridRow}}" >
<Style.Triggers>
<DataTrigger Binding="{Binding Alert_Level}" Value="1">
<Setter Property="Background" Value="LightYellow" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.ItemContainerStyle>
<DataGrid.Columns>
...
</DataGrid.Columns>
<DataGrid>
Mark Salsbery
|
|
|
|
|
Thanks Mark,
I tried that with no luck. I found the issue the value of Alert_Level was not numeric. Once I changed it to an int everything worked fine. Thanks for your help.
|
|
|
|
|
By default listbox list items in vertical. Now I want to list them in horizontal. I remember this can only be set in ListBox's Style. But I forget the full name of the Property and can not find it out in the past 2 hours.
Anyone know this property name?
|
|
|
|
|
Put the ItemsPresenter inside a Stackpanel with horizontal orientation.
|
|
|
|
|
Is that better (or different) to using a contentpresenter, and I used a wrappanel as there were quite a few images.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If a VirtualizingStackPanel has been used, I suppose there might be a performance benefit in terms of loading a large amount of data together (inside an ItemsControl ). A ListBox uses this panel by default.
Otherwise I'm not aware of any differences.
|
|
|
|
|
Thanks guys.
My design intention is listbox inside listbox. The items of the outer listbox binds with days. so it is better let days shown horizontal. Items of inner listbox binds with things to do in specific day. So If only a property setting can achieve it, it will save time and maintainace effort.
|
|
|
|