|
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.
|
|
|
|
|
Maybe this?
<ListBox >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Mark Salsbery
|
|
|
|
|
Mark has given you the "correct" answer here. All you need to do is override the ItemsPanelTemplate. There is no need to re-invent the wheel as other posters have suggested.
|
|
|
|
|
Hi, I have a ListBox bond to a collection of following objects with string and bool property:
class Item
{
public string Text {get;set;}
public bool IsBold {get;set;}
}
The DataTemplate is simple enough:
<DataTemplate>
<TextBlock Text="{Binding Text}" />
</DataTemplate>
(could actually use DisplayMemberPath instead, I know)
Now, I want those items that have IsBold == true to be bold-faced. As in WPF, where you add a simple DataTrigger that sets FontWeight=Bold on the TextBlock if IsBold is true.
Is something like this possible in Silverlight and what is the recommended approach? Thanks, H.
|
|
|
|
|
You could always bind a DataTrigger inside a style to do this, so you would end up with something like this:
<TextBlock Text="{Binding Text}">
<TextBlock.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Text}" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock> Note that I just typed this up in the browser window, so the syntax may need a minor tweak.
|
|
|
|
|
Would have been cool is Silverlight supported triggers at all, there is no Style.Triggers collection...
I'll do some digging, but honestly I didn't expect I'll spend so much time on such a simple matter you just take for granted in WPF.
|
|
|
|
|
I know it's an inelegant hack, but you could always use a value converter here.
|
|
|
|