|
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.
|
|
|
|
|
I have a treeview in WPF bound to a list of TreeItemEntity objects:
public class TreeItemEntity : _EntityBase
{
public string Caption { get; set; }
public string Description { get; set; }
public string ImageName { get; set; }
public bool IsExpanded { get; set; }
public TreeItemType ItemType { get; set; }
public List<TreeItemEntity> Children { get; set; }
}
In the XAML I have
<Window.Resources>
<HierarchicalDataTemplate DataType="{x:Type entities:TreeItemEntity}"
ItemsSource="{Binding Path=Children}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageName}"
Height="16"
Width="16"
Margin="0,0,3,0"/>
<TextBlock Text="{Binding Path=Caption}">
<TextBlock.ToolTip>
<ToolTip>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label FontWeight="Bold"
Content="{Binding Caption}"/>
<Label Content="{Binding Description}"/>
</StackPanel>
</StackPanel>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
</Window.Resources>
and
<telerik:RadTreeView x:Name="tvwTree"
Grid.Row="2"
Grid.Column="0"
ItemsSource="{Binding TreeData, Mode=TwoWay}"
SelectedItem="{Binding SelectedTreeItem, Mode=TwoWay}"/>
The question is, how do I bind to the TreeItemEntity's IsExpanded property?
Everything makes sense in someone's mind
|
|
|
|
|
You need to declare a style that targets a TreeViewItem or whatever telerik calls it and bind the IsExpanded in there.
|
|
|
|
|
That did it.
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
I have the following code from inside the UserControl.cs:
public void wait()
{
int i = 0;
while (i < 10)
{
i++;
System.Threading.Thread.Sleep(1000);
}
}
private void IsLoaded(object sender, RoutedEventArgs e)
{
wait();
}
I just want to wait 10 seconds AFTER the layout is rendered(you can see the buttons).
If i execute the code now, it will first wait 10 seconds and then it will render the layout.
I already tried with IsLoaded event for UserControl as you can see in the text and it is not working.
Now, the question I asked was in another context. The real situation is like this:
I have a Window from where I render different(Children.Add(UserControl)) UserControls after doing different calculations in the MainWindow.
The problem is that when I try to update a TextBlock from one of the UserControls by using a Method from the parent Window, the visual update(the text being modified) takes place at the end of the method. And because the operations inside the method takes a few second, a lag between action and display appears.
I have tried: UpdateLayou() after updating but it is not working.
Is there any possible way to render a UserControl immediately after I update one of its fields ?
I need to work using this architecture because I work with Windows Messages in WndProc.
|
|
|
|
|
rdinca wrote: Is there any possible way to render a UserControl immediately after I update one of its fields ?
You can use INotifyPropertyChanged to trigger an update on the UI.
However, on the whole, forcing a delay of 10seconds as the UI is refreshing is really not a good way to code.
You can use an asynchronous call and refresh the UI once the data returns from this call but putting in a delay is not a good practice at all.
|
|
|
|
|
As I told you, the code is just an example made up by me in order to get the question right.
Please read the entire post and if you don't understand what I need I will made up a new example based on the real coding needs.
Thank you,
Adrian
|
|
|
|