|
Mark Salsbery wrote: So you got it working now? How did you reference an assembly that wasn't installed?
No not got it working yet.As i downloaded the "April2010Toolkit.zip", that contains the System.Winodws.Control.Input.Toolkit.dll file, and i referenced to this.
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
|
|
|
|
|
I'm confused. You stated "i didn't installed the toolkit". You need to install it to reference the correct assembly since that's where the control implementation is.
So if you did install it, what's not working?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
I am using a Silverlight enabled WCF Service with the following attribute:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
It has a method say
[OperationContract]
public IEnumerable<Entity> GetAllEntities();
Sometimes I want to call this method multiple times within short span of time.. as WCF calls from Silverlight have to be asynchromous, the second call ends up getting called before the first one returned with the results. This results into the UserState getting corrupted. I find that the UserState of one of the calls gets overwritten by that of another call. I find this problem when the calls return and I extract the UserState from the EventArgs.
This seems to be a concurrency problem. I know we should avoid design which causes such multiple calls in Silverlight, but in some cases you just have to. Is there any workaroung/ solution to this problem?
Pankaj Chamria
|
|
|
|
|
Well, call the second service once the first one executes. No other choice.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Just asking....the UserState you refer to is your object right?
Like Abhinav S mentioned, you need to chain the asynchronous calls.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You mean the UserState on the server, right?
Either you need to write the service so that it can cope with being run concurrently, or wrap the content of that method with lock(UserState){ ... }. (You don't want to use [Synchronized] because it should be able to run concurrently for different users, even if making it work concurrently for the same one is too hard.) Obviously, the first way is preferred.
I'm guessing your method is actually not just a 'GetAllXxx' but instead updates some server state, because there should be no problem with doing multiple gets in parallel, and also you would not need to call that multiple times (the result could be cached).
Can you explain a bit more about what the service method is doing and why you need to call it multiple times? I would expect that it would be possible to bundle the requests up into a single service call in some way, reducing network traffic as well as reducing your concurrency issues. But you should still write a robust service regarding concurrency.
|
|
|
|
|
I have a datagrid where I have two buttons on each row - one for moving a row up and one for moving a row down.
Each button has a command for allowing the user to move the selected row in either direction. The problem that I am facing is that it not working. I think the problem that I may have is that the other controls (combo boxes) on the rows are bound to data sources through the MVVM model where I am manipulating the rows on the code behind of the XAML thinking this would be the logical place in which to do it.
The code I have for one of the buttons is below:
private void MoveRowDown(object sender, ExecutedRoutedEventArgs e)
{
int currentRowIndex = dg1.ItemContainerGenerator.IndexFromContainer(dg1.ItemContainerGenerator.ContainerFromItem(dg1.SelectedItem));
if (currentRowIndex >= 0)
{
this.GetRow(currentRowIndex + 1).IsSelected = true;
}
}
private DataGridRow GetRow(int index)
{
DataGridRow row = (DataGridRow)dg1.ItemContainerGenerator.ContainerFromIndex(index);
if (row == null)
{
dg1.UpdateLayout();
dg1.ScrollIntoView(selectedAttributes.Items[index]);
row = (DataGridRow)dg1.ItemContainerGenerator.ContainerFromIndex(index);
}
return row;
}
|
|
|
|
|
Instead of working with the grid you should work with the data. Add a sort field to the class used to populate the grid and manipulate the order in the VM.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to populate a TreeView dynamically during runtime of my program.
The WPF TreeView is for me very confusing and I can't really find any easy and simple guide. I hence this thread will be long because I have lot's of questions. Let's take them one by one.
My XAML is just:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TreeView Name="tvTree"></TreeView>
</Grid>
</Window>
My C# code is:
namespace WpfApplication1
{
public partial class MainWindow : Window
{
List<Person> persons;
public MainWindow()
{
InitializeComponent();
persons = new List<Person>();
persons.Add(new Person("Person1"));
persons.Add(new Person("Person2"));
persons.Add(new Person("Person3"));
persons.Add(new Person("Person4"));
persons.Add(new Person("Person5"));
tvTree.ItemsSource = persons;
}
}
public class Person
{
string name;
public Person(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
}
}
}
This will actually populate the TreeView with five TreeViewItems:
WpfApplication1.Person
WpfApplication1.Person
WpfApplication1.Person
WpfApplication1.Person
WpfApplication1.Person
This was somewhat expected since the TreeView read the ToString() method from my Person class.
But can I make the TreeView read the person's name from the Name property instead? I don't want to override the ToString() method to do this. I would like to use the Name property and connect that property to the XAML code.
|
|
|
|
|
In order to use the TreeView simply in WPF, it's important to understand that a tree represents a hierarchy of information. Another important concept to remember is that you are going to represent the hierarchy by changing the template of the control to display the data in a different fashion. I've deliberately used those words because the thing I want you to remember is that you can change the appearance of data using a DataTemplate , and that as you have a hierarchy of data in the TreeView , it takes a HierarchicalDataTemplate (even though you are only using one level of data, it has to cater for multiple levels).
So, we have a HierarchicalDataTemplate - how do we actually code this in our XAML? Well, we need to apply this to the template for each item (or the ItemTemplate ), so you would add something in that represented a single item. In this case, let's use a TextBlock . This would look like:
<TextBlock Text="{Binding Name}" /> That's all we need to do to actually bind to the name, but where do we put this? Well, we know that we need to add it into a HierarchicalDataTemplate , so let's add that into our TreeView . It looks like this:
<TreeView Name="tvTree">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:Person}">
<Grid>
<TextBlock Text="{Binding Name}" />
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView> Now, you might be wondering why we put a DataType against the HierarchicalDataTemplate . Well, as it's a DataTemplate and there may be multiple different types of data under the tree nodes, the DataType tells WPF which particular type of data to render this TreeView out against. This allows you to build an incredibly complex hierarchy of data in the TreeView , and yet have small self-contained DataTemplate elements reshaping the data easily (don't forget to add a namespace reference so that it knows where to pick Person up from).
I hope this helps.
|
|
|
|
|
I know what the TreeView can do in WPF, I just don't know how to do it. So I start very simple and continue on that.
Thanks by the way for the code, it did the trick when I found out how to make a XAML-namespace reference
xmlns:local="clr-namespace:TreeView"
Notice I have change my namespace from WpfApplication1 to TreeView
Now I want to implement the TreeView to add sub TreeViewItems for some of the already existing TreeViewItems. I have changed my C# to:
namespace TreeView
{
public partial class MainWindow : Window
{
List<Person> persons;
public MainWindow()
{
InitializeComponent();
persons = new List<Person>();
Person p1 = new Person("Person1");
p1.Children.Add(new Person("Children1"));
p1.Children.Add(new Person("Children2"));
persons.Add(p1);
persons.Add(new Person("Person2"));
Person p3 = new Person("Person3");
p3.Children.Add(new Person("Children1"));
persons.Add(p3);
persons.Add(new Person("Person4"));
persons.Add(new Person("Person5"));
tvTree.ItemsSource = persons;
}
}
public class Person
{
List<Person> children = new List<Person>();
string name;
public Person(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
}
public List<Person> Children
{
get { return children; }
set { children = value; }
}
}
}
As expected no XAML code is written to handle the Children list so no sub TreeItemView is visible. How shall I implement that in my XAML code?
|
|
|
|
|
This one's going to appear a little bit magic right now. If you add ItemsSource="{BindingChildren}" to your HierarchicalDataTemplate definition, you'll automatically get the children added into the correct location. This turns your TreeView into this:
<TreeView Name="tvTree">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate
ItemsSource="{Binding Children}"
DataType="{x:Type local:Person}">
<Grid>
<TextBlock Text="{Binding Name}" />
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
|
|
|
|
|
I cannot understand how that XAML code works but it sure does Even with several multiple levels of children. Kick ass!
Thanks a lot! I will try to implement this into a more complex system of classes where the data is stored in.
|
|
|
|
|
You are welcome. The key is actually the DataType, the ItemsSource tells it where to get the data, and in the case of the top level elements it fails to find that item, so it falls back to the default ItemsSource (the one specified against the TreeView).
|
|
|
|
|
I have one further problem concerning displaying items in the TreeView. Adding one more collection for each Person, the Item collection.
The entire C# code is:
namespace TreeView
{
public partial class MainWindow : Window
{
List<Person> persons;
public MainWindow()
{
InitializeComponent();
persons = new List<Person>();
Person p1 = new Person("Person1");
Person c1 = new Person("Children1");
c1.Items.Add(new Item("Telephone"));
c1.Items.Add(new Item("Game console"));
p1.Children.Add(c1);
p1.Children.Add(new Person("Children2"));
p1.Items.Add(new Item("Car"));
p1.Items.Add(new Item("Computer"));
persons.Add(p1);
tvTree.ItemsSource = persons;
}
}
public class Person
{
List<Person> children = new List<Person>();
List<Item> items = new List<Item>();
string name;
public Person(string name)
{
this.name = name;
}
public string Name
{
get { return name; }
}
public List<Person> Children
{
get { return children; }
set { children = value; }
}
public List<Item> Items
{
get { return items; }
set { items = value; }
}
}
public class Item
{
string type;
public Item(string type)
{
this.type = type;
}
public string Type
{
get { return type; }
}
}
}
Notice the List<item> collection in the Person class. Can I display that collection in the TreeView at the same time as the List<person> Children collection?
How should I implement that in my XAML code?
My current XAML code:
<Window x:Class="TreeView.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TreeView"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TreeView Name="tvTree" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,5,0,0" Width="300" Height="300">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type local:Person}">
<Grid>
<TextBlock Text="{Binding Name}" />
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
</Window>
The result should be something like this:
Person1
Chilrden1
Telephone
Game console
Chilrden2
Car
Computer
modified on Monday, July 4, 2011 7:20 AM
|
|
|
|
|
Hello,
I am using WCF + Silverlight. Can anyone can tell me how to make sync call to WCF methods?
Thanks in Advance..
|
|
|
|
|
You can't make a synchronous call from Silverlight to WCF. Silverlight demands that the calls are made asynchronously because it runs on the browser UI thread, so you could end up blocking the browser if you made a long running synchronous call.
Right - that's the official party line out the way. In reality, you can make synchronous calls, you just can't use the WCF RIA features to do it. My good friend and one of the brightest human beings to walk the planet, Daniel Vaughan, came up with a fascinating method to do just this. You can find details on how to do this here[^].
|
|
|
|
|
hi
I my SL4 app i created an usercontrol and i'm showing it in a page.
This usercontrol has some button(created dinamically) and a public property named "SelectedValue" (that change when a button is clicked and its value is Button.Tag).
I want to notify the page (somehow, through event) that the "SelectedValue" is changed. How can i???
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
|
|
|
|
|
jadughar wrote: I want to notify the page (somehow, through event) that the "SelectedValue" is changed. How can i???
You can add an event to your usercontrol class which is raised when the property is changed. The page can subscribe to this event. For example:
public event EventHandler<EventArgs> SelectedValueChanged;
object _selectedValue;
public object SelectedValue
{
get { return _selectedValue; }
set
{
if (_selectedValue != value)
{
_selectedValue = value;
EventHandler<EventArgs> evnt = SelectedValueChanged;
if (evnt != null)
evnt(this, new EventArgs());
}
}
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark
Thanks for the answer!!! It work fine !!
I tried with similar code but it didn't work. I would like to post my code and want to know what was wrong.
Anyway your sample is awesome!!!
thanks again
bye
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
|
|
|
|
|
jadughar wrote: I would like to post my code and want to know what was wrong.
Go ahead!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
this was the code giving error :
public event RoutedEventHandler SomethingHappened;
int progressivoSelezionato = 0;
public int valoreSelezionato
{
get { return this.progressivoSelezionato; }
set
{
this.progressivoSelezionato = value;
RoutedEventHandler myHandler = SomethingHappened;
if (myHandler != null)
myHandler(this, new RoutedEventArgs());
}
}
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
|
|
|
|
|
It's not a routed event so I wouldn't use RoutedEventHandler.
Still I would think it would work but I could be wrong - didn't try it
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi Mark
I didn't understand ur last post.
Anyway ur sample is working perfectly.
My sample is giving error.
Anyway what's the difference between RoutedEvent and the Event(that u used in ur sample) ??
"For as long as men massacre animals, they will kill each other. Indeed, he who sows the seed of murder and pain cannot reap joy and love." Pythagoras
|
|
|
|