|
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.
|
|
|
|
|
This was actually a simple problem in th end, I assumed that the [Required] annotation would check that the association was present and not null. It seems that all it actually does is check that in this case that FrequencyId is not null. And there was the problem in that I was using a long and not a nullable long (long?). Once I made the change to make them nullable the validation started working as expected even with the bindings which made no sense to me. If anyone could explain them that would be great!
Phil
|
|
|
|
|
Hi there,
How can I add a blinking pushpin to my bing map control using StoryBoard?
Thanks
|
|
|
|
|
How do i bind Canvas.Left -= Math.cos(x) * 125 formula to objects.
x : rotation of rectangle and will increased from 0 to 60 degrees by a storyboard.
<Rectangle x:Name="img1" Canvas.Left="{Binding Converter= {StaticResource PositionConverter1}, ConverterParameter=60}" Canvas.Top="150" Fill="#FF5B5BAF" Stroke="Black" Width="250" Height="250">
<Rectangle.Projection>
<PlaneProjection RotationY="60"/>
</Rectangle.Projection>
</Rectangle>
ConverterParameter=60 must be the RotationY of StoryBoard
|
|
|
|
|
Thanks for reply but how do make ConverterParameter awared of the value changed by StoryBoard
<Storyboard x:Name="sbRotate" AutoReverse="False">
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:00"
Duration="00:00:01"
Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="60"/>
<EasingDoubleKeyFrame KeyTime="00:00:01" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
here is converter
public class PositionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double currentLeft = (double)value;
double angle = (double)parameter;
return currentLeft -= Math.Cos(angle) * 125;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double currentLeft = (double)value;
double angle = (double)parameter;
return currentLeft += Math.Cos(angle) * 125;
}
}
|
|
|
|
|
You gave me the idea and I solved the problem. Thank you very much Here is the solution for everyone :
DispatcherTimer timer = new DispatcherTimer();
public MainPage()
{
InitializeComponent();
timer.Interval = new TimeSpan(0, 0, 0, 0, 50);
timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
if (count <= 20)
{
angle = DegreeToRadian(count * 3);
newleft = (1 - (Math.Cos(angle))) * 250;
img1.SetValue(Canvas.LeftProperty, currentleft-newleft-30);
count++;
}
else
{
count = 1;
timer.Stop();
}
}
|
|
|
|
|
I try to describe the scenario :
I’m passing a populated Dictionary<string,string> to the DomainService query to get the filtered data.
The problem is that the data don’t get filtered in proper way if I filter by more than one parameter. The code seems to be correct. I couldn’t realize what can be the problem.
Client Side:
<pre>
Private DomainContext context = new DomainContext();
Private Dictionary<string,string> searchParameters = new Dictionary<string,string>();
Public MainPage()
{
InitializeComponent();
this.searchParameters.Add("ProductCategoryID","3");
this.searchParameters.Add("ProductModelID","1");
this.context.load<Product>(this.context.GetProductQuery(this.searchParameters));
}
Server Side:
Public IQueryable<Product> GetProduct(Dictionary<string, string> searchParameters)
{
IQueryable<Product> queryableData = ObjectContext.Product;
int idValue = 0;
if (searchParameters.ContainsKey("ProductCategoryID"))
{
idValue = int.Parse(searchParameters["ProductCategoryID"]);
queryableData = queryableData.Where(i => i.ProductCategoryID == idValue);
}
if (searchParameters.ContainsKey("ProductModelID "))
{
idValue = int.Parse(searchParameters["ProductModelID"]);
queryableData = queryableData.Where(i => i.ProductModelID == idValue);
}
return queryableData;
}
|
|
|
|
|
Putting a breakpoint i noticed that after the first "Where" there are some entities in "QueryableData" but after executing the second "Where" there are no entities in QueryableData whereas there should be some entities.
|
|
|
|
|
This compiled & runs, but nothing happens when I click a tree node. It works if I do it in XAML, just not in te code behind:
private object _SelectedItem = null;
public object SelectedItem
{
get { return _SelectedItem; }
set
{
if (_SelectedItem != value)
{
_SelectedItem = value;
RaisePropertyChanged("SelectedItem");
itemSelected();
}
}
}
and
RadTreeView tree = new RadTreeView
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
ItemsSource = Clients,
SelectedItem = this.SelectedItem,
Name = "tvwClientProjects"
};
What's wrong with the SelectedItem???
Everything makes sense in someone's mind
|
|
|
|
|
When you do it in the XAML, you are creating a binding... in your C# code you are just copying the value over one time.
You need to do something like:
Binding binding = new Binding("SelectedItem");
binding.Source = this;
binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
binding.Mode = BindingMode.TwoWay
SetBinding(RadTreeView.SelectedItemProperty, binding);
P.S. not sure why you are creating the tree in the code behind, but the above will work. There is probably a much cooler way to do what you are trying. You almost never need to create controls in the code behind.
|
|
|
|
|
That did it. Thank you!!!
Everything makes sense in someone's mind
|
|
|
|
|
That's not a binding - you're just setting the property's value.
Maybe something like
RadTreeView tree = new RadTreeView
{
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
ItemsSource = Clients,
Name = "tvwClientProjects"
};
Binding binding = new Binding("SelectedItem");
binding.Mode = BindingMode.TwoWay;
tree.SetBinding(RadTreeView.SelectedItemProperty, binding);
Mark Salsbery
|
|
|
|