|
Wouldn't you just have a ProjectType obejct in your ProjectEntity and bind that to the ComboBox SelectedItem in two-way mode?
|
|
|
|
|
Ok, I have this
<ComboBox ItemsSource="{Binding Path=DataContext.ProjectTypes,
RelativeSource={RelativeSource FindAncestor, AncestorType={ x:Type views:ClientListView}}}"
SelectedItem="{Binding Path=DataContext.SelectedProjectType,
RelativeSource={RelativeSource FindAncestor, AncestorType={ x:Type views:ClientListView}}, Mode=TwoWay}"/>
The property in the VM is being set, but it seems like I would need some logic somewhere to know which ProjectEntity the user was changing.
Can you elaborate a bit?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Doesn't each item in your ListBox have a ComboBox? That's what it looks like from your XAML. So each item in the ListBox would need to have a SelectedProjectType and you would bind to the item one, not the view one.
|
|
|
|
|
I'm giving a try to VisualState in my template for a WP7 app.
I have an ExpanderView and I'd like to have a little arrow in the header showing the state (expanded or not) and rotate it smootly from up to down when IsExpanded change value.
I have an attached property WpfUtils.VState which call VisualStateManager.GoToState(target) when a binded value change.
1st problem it should target a Control but I'm trying to update an Image ...
I "worked around it" (hopefully, doesn't work anyway) by templating the container object.
2nd problem, it's just not working!
Here is my XAMl, any idea?
<toolkit:ExpanderView
x:Name="eview"
gwpf:WpfUtils.VState="{Binding IsExpanded, Converter={StaticResource ccvt}, RelativeSource={RelativeSource Self}}"
>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="MyStates">
<VisualState x:Name="MyCollapsedState"/>
<VisualState x:Name="MyExpandedState">
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Header.RenderTransform.Angle"
Duration="0:0:0.5" From="-90" To="90"/>
<!--
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<toolkit:ExpanderView.Header>
<StackPanel Orientation="Horizontal">
<Image Width="36" locv:ThemedImage.Path="appbar.next.rest.png" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<RotateTransform x:Name="ArrowExpandT" Angle="-90"/>
</Image.RenderTransform>
</Image>
<TextBlock
Text="{Binding Local.NewItem, Source={StaticResource strings}}"
FontSize="{StaticResource PhoneFontSizeLarge}"
VerticalAlignment="Center" Margin="8"/>
</StackPanel>
</toolkit:ExpanderView.Header>
<StackPanel Orientation="Vertical">
<locv:ItemView x:Name="NewItemUI" />
<!--
<Button
VerticalAlignment="Bottom" HorizontalAlignment="Right"
Content="{Binding Local.Add, Source={StaticResource strings}}"
Click="DoAddItem"/>
</StackPanel>
</toolkit:ExpanderView>
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi,
I have a silver light application. I have some master data in database which is using extensivly on application especially when i print crystal reports. So i decided to store data on Server( through session etc) or on client to avoid database trips. I want to ask which is best option from perfomance point of view
Option 1: Store all data on server( through session or application variables etc) and get data from server when needed for example while printing reports( I am using Crystal Reports12)
Option2: Store all data on client ( e.g create a collection in silverlight on client and store all currencies in that collection) and when i want to print report and want to use that data pass this data( currency collection) to server along with other data( other arguments needed on server) through WCF services ( I am using WCF Services)
Thanks
|
|
|
|
|
You should also look at the Isolated Storage option.
Here, you can store some amount of data (so long as it is not too large) and make it persist for some time (unless the client clears this storage area).
|
|
|
|
|
Thank you for suggestion. I want to get/transfer this data from database when user login and clears out when he log off ( As data may be change any time). Should i still consider Isolated storage option? and second thing storing data in Isolated storage means transfer data on client is good option . Am i right?
Thank you & Best regards
|
|
|
|
|
If the data is liable to change during the use of the application then you shouldn't really consider storing it in isolated storage. Take, for instance, stock prices - these change rapidly, so the data for this should be retrieved from elsewhere (e.g. a web service, or database if you are the one controlling the stock prices). If the setting is something like a user preference, then it does make sense to store this locally, but with it synchronised back to the server when the user updates it.
|
|
|
|
|
Thanks you for your suggestion.
Data can be changed but not so frequently. You can say that when user login then if we have fetched data from database then its ok until he logg off( if data is changed between user login and log out then no need to update/syncronize). I shall use this data on different crystal reports which will print from server. so what i am thinking instead of fetching this data from database i shall use this from session (stored in any sevrver object) but other option may be tranfer all data to client machine and send back to server when it is needed to print on crystal report or wherever used on server( to decrease load on server). Which option will be best Either to store data on server or on client
|
|
|
|
|
Think about it this way. If you store the data on the client and you have lots and lots of clients, then that's a lot of traffic you're going to be sending out, just to send it back to the server when you need to print the report. Is this acceptable to you, in terms of performance.
Please note that there is no right answer that we can give you, it's going to depend entirely on your requirements, system architecture and so on.
Saying that, if it were me, I wouldn't be transferring it backwards and forwards.
|
|
|
|
|
Anyone have an example of how to handle events using MVVM? Specifically, I'd like an event defined in XAML to be handled in the ViewModel.
Everything makes sense in someone's mind
|
|
|
|
|
1) download the Blend SDK (you only need System.Windows.Interactivity.dll)
2) steal an EventToCommand mapper (such as the one in MVVMLight or Cinch for example)
3) in XAML, add the namespace:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
4) on the owning object you would do something like:
<ListView>
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemContextMenuOpening">
<local:EventToCommand Command="{Binding ItemContextMenuOpeningCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListView>
|
|
|
|
|
Ok, can you further explain what you mean by "EventToCommand mapper". I have MVVMLight, but I don't know what an EventToCommand mapper is.
Everything makes sense in someone's mind
|
|
|
|
|
Ok, I got most of it, but I still have something wrong.
My XAML:
<Window x:Class="Events.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:entities="clr-namespace:Events"
xmlns:g="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate DataType="{x:Type entities:Customer}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding CustomerName}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding Customers}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="ListBoxItem.MouseDoubleClick">
<g:EventToCommand Command="{Binding DoubleClickCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
</Grid>
</Window>
and my code behind
using System.Collections.ObjectModel;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
namespace Events
{
public class MainWindowViewModel : ViewModelBase
{
private ObservableCollection<Customer> _Customers = new ObservableCollection<Customer>();
public ObservableCollection<Customer> Customers
{
get { return _Customers; }
set
{
if (_Customers != value)
{
_Customers = value;
RaisePropertyChanged("Customers");
}
}
}
private ICommand _DoubleClickCommand;
public ICommand DoubleClickCommand
{
get
{
if (_DoubleClickCommand == null)
{
_DoubleClickCommand = new RelayCommand(doubleClicked);
}
return _DoubleClickCommand;
}
}
public MainWindowViewModel()
{
Customers.Add(new Customer { Id = 0, CustomerName = "Jack Smith"});
Customers.Add(new Customer { Id = 1, CustomerName = "Pete Jones" });
Customers.Add(new Customer { Id = 2, CustomerName = "William Jackson" });
}
private void doubleClicked()
{
}
}
}
The doubleClicked() method is never called.
What am I missing???
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: <i:EventTrigger EventName="ListBoxItem.MouseDoubleClick">
You can't do nested events like that. You can do "MouseDoubleClick" which is going to be the ListBox one. If you want to map to the ListBoxItem one, you have to define a style that targets the ListBoxItem and put it in there.
modified 14-Feb-12 18:03pm.
|
|
|
|
|
That did it.
With the "PassEventArgsToCommand" can't I pass along the Id of the customer I double clicked? if so, how so that done?
I think what I'm missing the code behind. I can't seem to figure it out.
Everything makes sense in someone's mind
|
|
|
|
|
The PassEventArgsToCommand="true" is going to pass the EventArgs object to your command. So you would use RelayCommand<T> where T is the type of event args thrown up by that event. In your case, sender is going to be the ListBoxItem.
|
|
|
|
|
ya, I figured it out. The syntax is new to me, but I got it.
Here's what I have now:
<ListBox x:Name="myListBox"
ItemsSource="{Binding Customers}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<g:EventToCommand Command="{Binding DoubleClickCommand}"
CommandParameter="{Binding SelectedItem, ElementName=myListBox, Mode=OneWay}"
PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
and it's now passing the double-clicked customer to the handler method.
Truth is, the same could be accomplished by binding the list's SelectedItem.
Thanks!
Everything makes sense in someone's mind
|
|
|
|
|
What exactly are you trying to do?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
...learn how to handle events using MVVM
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: learn how to handle events using MVVM
A generic answer gets a generic response. Your question is beyond a simple forum post. You will most likely have to do some research. There are a couple of approaches. One approach is to use the expression blend libraries as SledgeHammer suggested. Download from codeplex. Or you are going to be writing a bunch of attached behaviors.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
|
I'm trying to figure out how to style my list box items as hyperlinks, but I can't seem to find an example. I don't really know what I'm looking for. Anyone have any example of this?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
For a hyperlink button, just take a look the HyperLink button.
Here[^] is a sample.
To add hyperlinks to a list, include this in your DataTemplate - here is a very basic code snippet just to get you started.
<DataTemplate>
<Grid>
<HyperLink />
</Grid>
</DataTemplate>
|
|
|
|
|
We have in our application columns wich depend of each others, thats why we wanna them stay together if the user drag a column.
In WPF if you drag a column u see it with low opacity at your mousecursor bevor your drop it, now we would like to see the other column too(wich depend of the draged column) moving with low opacity when the user drag the first column.
Any ideas?
Thanks a lot.
cheers, negada.
|
|
|
|