|
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.
|
|
|
|
|
That is what I used for the time being - BooleanToFontWeightConverter, nice - but I am looking for a more systematic approach because I am sure that design requirements will get more complicated than FontWeight=Bold.
|
|
|
|
|
Potentially, you could wrap things into a nice Blend attached behavior. I've done this to get round SL deficiencies in the past.
|
|
|
|
|
I'm trying to understand how validation works for a combo box when its ItemsSource is bound to a ObserableCollection of complex types. I am using RIA as the serivce to connect the client tier to the middle tier. Also not sure if this makes a difference the combobox control is inside a dataform. I have done alot of reading on this and found this article to be the most useful: http://www.run80.net/?p=93
So firstly my entity: I have a field decorated like so:
[Required]
public virtual long FrequencyId { get; set; }
[Include]
[Association("TreatmentFrequencyToTreatmentRecordAssociation", "FrequencyId", "Id", IsForeignKey = true)]
public virtual TreatmentFrequency Frequency
{
get
{
return this.frequency;
}
set
{
this.frequency = value;
if (value != null)
{
this.FrequencyId = value.Id;
}
}
}
Now I belive that I cannot set the [Required] annotation on an association but instead on the foreign key id (what the above article says).
The actual Treatment Frequency class looks like this:
public class TreatmentFrequency
{
[Key]
public virtual long Id { get; set; }
[Required]
[StringLength(10)]
public virtual string Code { get; set; }
[Required]
[StringLength(40)]
public virtual string Name { get; set; }
public override bool Equals(object obj)
{
obj = obj as TreatmentFrequency;
if (obj == null)
{
return false;
}
return this.Id == ((TreatmentFrequency)obj).Id;
}
public override int GetHashCode()
{
return this.Name.GetHashCode();
}
}
I have overriden the Equals and GetHashCode method becuase in another article it said that when in a collection you need to override the equals to match on the key otherwise when you use SelectedItem although all the values would be the same between the item in the collection and the selecteditem they would be two different instances and thus not match with the default implementation of Equals.
Now my xaml looks like this:
<df:DataField Label="Frequency">
<ComboBox SelectedItem="{Binding Path=CurrentItem.Frequency, Mode=TwoWay}" ItemsSource="{Binding Path=Frequencies}" DisplayMemberPath="Name" SelectedValue="{Binding Path=CurrentItem.FrequencyId, Mode=TwoWay}" SelectedValuePath="Id"/>
</df:DataField>
To be honest the above doesn't make much sense to me, I could remove SelectedValue and SelectedValuePath and the form would still work as expected (without validation) I thought that Selected Value would point to the complex type E.g. CurrentItem.Frequency and then the SelectedValuePath would be the underlying "Name" property. However I also understand what the author is trying to do in that the [Required] tag isn't on the association but the foreign key id E.g. CurrentItem.FrequencyId, so it must have to go somewhere.
Now a final compelexity is that this form is part of a wizard so I am not able to validate the entire object, instead I manually have to validate certain field which are only being populated in this particular wizard step. To do this I created the method:
public void ValidateProperty(object value, string propertyName)
{
var results = new List();
Validator.TryValidateProperty(value, new ValidationContext(this.TreatmentRecord, null, null) { MemberName = propertyName }, results);
foreach (var error in results)
{
this.TreatmentRecord.ValidationErrors.Add(error);
}
}
In my view model I have a method IsValid which is called before the wizard is allowed to navigate to the next step and then I call the above method like so:
public bool IsValid
{
get
{
this.treatmentRecordWizardContext.ValidateProperty(this.treatmentRecordWizardContext.TreatmentRecord.Frequency, "Frequency");
this.treatmentRecordWizardContext.ValidateProperty(this.treatmentRecordWizardContext.TreatmentRecord.FrequencyId, "FrequencyId");
this.OnPropertyChanged(() => this.CurrentItem);
if (this.treatmentRecordWizardContext.TreatmentRecord.ValidationErrors.Count == 0)
{
return true;
}
return false;
}
}
With all of the above code the validation is completly ignored when the combobox is left empty. I have not templated the combobox itself so I am really at a loss as to why its not working and really which part of the solution is at fault, is it the bindings or is it the entitys in the RIA not defined correctly!
Hope someone can help I've spent far too long trying to get this to work, I assume this must be done reqularly by other developers so I'm hoping its a simple fix.
|
|
|
|