|
Just uninstall silverlight toolkit and
install it from following path.
I think it has been overridden by older version or
when you installed vs 2010 it may conflicted with the
existing silverlight version.
And close vs 2010 b4 you install silverlight toolkit.
http://silverlight.codeplex.com/[^]
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Viewbox is supported in Silverlight 4 so you cant use it directly in Silverlight 3. If you want to use it in version 3, then you will need to use the Silverlight Toolkit.
-Mamta
|
|
|
|
|
I'm using the Silverlight 4 Tookit Expander all over the place. They are all contained within a ScrollViewer. Sometimes when I expand one of the Expander elements, the Expander.Header winds up above the top of the ScrollViewer and hence is not visible and so you can't see the title of the content that has been expanded. What I would like to do is center the Expander header vertically within the ScrollViewer viewport when I expand the Expander. To do this I have to set the ScrollViewer.VerticalOffset to the right value that will center the Expander in the ScrollViewer viewport.
So I think I understand the problem that needs to be solved. But I haven't found a solution. Hopefully it's simple and I'm just overlooking something.
The only ScrollViewer properties I've found that might be relevant to this problem are the following: ViewportHeight, VerticalOffset, ExtentHeight, and ActualHeight. I also have the mouse cursor Point relative to the Expander when the Expanded event takes place. But even with all this information, I don't seem to have the right information to compute what the VerticalOffset of the ScrollViewer should be.
SOLUTION: Chalk up my inability to solve this to plain and simple User Brain Damage. The solution was SMOP: a Small Matter Of Programming.
Most of the properties I identified above are not needed, only the following: VerticalOffset, ViewportHeight, and the Y coordinate of the mouse cursor position. Oh, yes! You have to perform the computation in the right event: Expander.SizeChanged, not Expander.Expanded. Only perform the offset if Expander.IsExpanded is true.
So the code in my SizeChanged event looks like this:
private void expander_SizeChanged(object sender, SizeChangedEventArgs e)
{
Expander expander = sender as Expander;
if (expander != null && expander.IsExpanded)
{
double viewportHeight = scrollViewer.ViewportHeight;
double verticalOffset = scrollViewer.VerticalOffset;
double mouseVerticalOffset = MouseCursorPosition.Y;
double newVerticalOffset =
verticalOffset - viewportHeight / 2 + mouseVerticalOffset;
scrollViewer.ScrollToVerticalOffset(newVerticalOffset);
}
}
FYI, MouseCursorPosition is one of my properties, set in my ScrollViewer's MouseMove event. Seems kind of expensive, but it doesn't seem to interfere with the UI response and I don't know of any other way to get the mouse cursor position.
|
|
|
|
|
fjparisIII wrote: Only perform the offset if Expander.IsExpanded is true.
Actually I like it better if you center the Expander whether or not it is expanded. Now all I have to do is animate the centering so that it doesn't jump to the middle so violently.
|
|
|
|
|
fjparisIII wrote: Now all I have to do is animate the centering so that it doesn't jump to the middle so violently.
Impossible, at least by using a Storyboard. The only thing you can animate with a Storyboard is a Dependency Property and the ScrollViewer's VerticalOffset property is read-only. Major bummer. Why did they do that???
Googled around a bit and I found two workarounds. First you can write a ScrollViewer extension adding a dependency property implemented using ScrollViewer.ScrollToVerticalOffset(). Second, you can bite the bullet and do it the old-fashioned way: use a DispatcherTimer, which itself would call ScrollToVerticalOffset().
|
|
|
|
|
Did you try setting the VerticalContentAlignment and the VerticalAlignment to stretch for the expander and for the scrollviewer?
My signature "sucks" today
|
|
|
|
|
Abhinav S wrote: Did you try setting the VerticalContentAlignment and the VerticalAlignment to stretch for the expander and for the scrollviewer?
No. What's that supposed to accomplish? The solution I posted works perfectly fine. Besides, I've moved beyond that now and am working on animating the scroll to the center of the viewport, using a DispatcherTimer . I've got it working beautifully, but I had to set the timer interval to 1/120 of a second to get a smooth scroll. 1/60 of a second for some reason produces a jerky scroll.
I've been experimenting with the duration. So far I like a duration of 0.2 seconds, producing 24 intervals. Each interval scrolls 15 vertical pixels within a viewport of 860 pixels (i.e. scrolling a little less than 430 pixels when the Expander is at the top of the viewport). Eminently smooth.
Anyhow, this animation stuff is far more interesting than centering the Expander , which as far as I'm concerned I solved to my satisfaction hours ago.
I'll show my animation code when I've sufficiently polished it. I've created a class to perform the animation, because I have about 100 Expander elements in 12 different classes, so I need to be clean about this.
|
|
|
|
|
fjparisIII wrote: VerticalContentAlignment and the VerticalAlignment to stretch
These are supposed to place a control within another control.
I would suggest you have a look at the documentation (for them) on msdn.
And you would need to set the properties to "center" and not "stretch" as I mentioned above.
I'm glad that you have managed to get this working using a workaround though.
My signature "sucks" today
|
|
|
|
|
Abhinav S wrote: These are supposed to... etc.
I know what they both do. I use them all the time, both in Silverlight and WPF. I just don't see their relevance to the problem I was trying to solve.
Abhinav S wrote: I'm glad that you have managed to get this working using a workaround though.
You're talking about the centering of the Expander s, correct? I'd hardly call my solution a "workaround." It's a straightforward solution, direct and to the point.
Maybe I didn't explain carefully enough what I'm trying to do. I have extensive product documentation on my Website. I have a product overview, ten tutorials, plus an "Easter egg" that gives background on how such a product ever came to be developed. Each document is initially presented as a list of Expander s within a ScrollViewer . The average list has about 8 Expander s and each Expander expands and collapses on average 8 lines of wrapping text per paragraph and maybe 5 or 6 paragraphs.
The problem was to vertically center an Expander header when the user clicks on it. However, doing that was just a matter of SMOP, nothing esoteric about it at all, and I shouldn't even have asked the question to begin with.
But then I immediately saw that the expansion/collapse took place so fast that it was disconcerting and that it needed to be animated. That's really the interesting part of this entire discussion, and I'm still working on it to capture all the end cases. Should have it all worked out sometime this morning, and then I'll present it under Tips and Tricks.
Anyhow, I don't see how VerticalContentAlignment would play a role in this, since I don't want to keep the content vertically aligned, but only vertically aligned when the user clicks on the Expander header, and only the header for that one Expander , not all of them.
|
|
|
|
|
|
Hi again!
As you can guess, i have been learning WPF.
I have a question about data-binding (I currently use Linq2Sql). Everything is OK, as long as I use a simple column-to-textbox or column-to-listbox binding.
1. How to perform a more complex data-binding? I would like to hold a more sophisticated Linq query in the logic/code layer (not in the presentation). I am interested in a two-way binding.
2. How to set a DataSource directly in Xaml? In most of tutorials something like this is proposed:
control.DataSource = _myObservableCollection;
However, if I want to have a data-bound combo box which is inside a DataTemplate of a listbox, it would be ugly to dig into a visual tree just to set a data source of each combo box in each listbox's item.
I know my message is messed, if you have any questions then please ask them (the questions).
Thanks --
Greetings - Jacek
|
|
|
|
|
See this article - some binding samples are discussed here. Most of them are through code, but there is an interesting scenario where binding is done by setting the datacontext in the xaml.
Hope others can provide some better examples / scenarios.
My signature "sucks" today
|
|
|
|
|
I tried the following code (template for a ListBoxVerbs ):
<DataTemplate x:Key="verbItem">
<ListBoxItem>
<StackPanel Orientation="Vertical">
<TextBox FontWeight="Medium" MinWidth="150" Height="26"
Margin="1" Text="{Binding Path=Singular3}" Style="{StaticResource EditableTextBox}"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="1">Odwrotność:</Label>
<!--<TextBlock Grid.Column="1" Text="{Binding Singular3}"/>-->
<ComboBox ItemsSource="{Binding Source=
{RelativeSource Mode=FindAncestor, AncestorType=ListBox}, Path=ItemsSource}"
SelectedItem="{Binding Path=Singular3}" Grid.Column="2">
<ComboBox.ItemTemplate>
<DataTemplate>
<ComboBoxItem>
<TextBlock Text="{Binding Path=Singular3}"/>
</ComboBoxItem>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</StackPanel>
</ListBoxItem>
</DataTemplate>
The emhazised ComboBox is supposed to display the same set of items as the parent ListBox . It does not, though.
Greetings - Jacek
|
|
|
|
|
I've run into similar problems before. I'm not sure why, but FindAncestor just doesn't seem to want to work sometimes. Might have something to do with the fact that you are using a data template. The workaround is to name your ListBox:
<Grid>
<Grid.Resources>
<x:Array
x:Key="strings" Type="core:String"
xmlns:core="clr-namespace:System;assembly=mscorlib">
<core:String>Hello</core:String>
<core:String>Goodbye</core:String>
</x:Array>
</Grid.Resources>
<ListBox Name="myList" ItemsSource="{StaticResource strings}">
<ListBox.ItemTemplate>
<DataTemplate>
<ComboBox
ItemsSource="{Binding ElementName=myList, Path=ItemsSource}"
SelectedIndex="0" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
You could also add a property to your Window and bind to that. Or, you can add a property, "Parent", to each item in the list that points back up to the list (in which case you can just bind to the parent property to get the parent list).
|
|
|
|
|
Hi,
i m new to this silverlight...Plz give any sample code for www.k12.com[^]..for menu pop up....using silverlight controls with mouse over the text is chnaging with links.
With Regards,
Thanks in advance.
Ch.Gayatri
|
|
|
|
|
Have you searched the internet for some samples?
I found one here - Reusable Silverlight 2 Popup Menu and I know there are plenty more.
If you want to make your popup look like any website, you need to write your own code for it.
My signature "sucks" today
|
|
|
|
|
yes i found but not exact wht i want
|
|
|
|
|
Hi
I know that we can add the Validator.ValidateProperty call inside the buisness object and decorate it as [Required] like as follows. Reference : http://blogs.msdn.com/b/nagasatish/archive/2009/03/22/datagrid-validation.aspx
[Required]
public string FirstName
{
get { return firstName; }
set
{
if (value != firstName)
{
Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "FirstName" });
firstName = value;
NotifyPropertyChanged("FirstName");
}
}
}
My problem with this approach is that auto generated classes do not contain any validation logic inside them. I am generating the classes from an xsd (XSD2Code utility) and have to use these DTOs because all layers are utilizing them.
Silverlight->WCF->Business layer->Data Access layer : All using common DTO classes
My questions are :
1. How can I incorporate validations for datagrid entry fields without adding them into plain classes?
2. Is there a way that I can add all these rules in xsd and have them written out inside classes?
Please advise. Thanks
AJ
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
Hello everyone,
I have the following peace of code in a WPF application.
System.Threading.ThreadStart threadstartdelegate = delegate()
{
for (int i = 0; i < 100; i++)
{
System.Threading.Thread.Sleep(1000);
OnlineClientListBoxItem item = new OnlineClientListBoxItem();
item.SetUserDetails(Name: "Client " + i.ToString(), Userid: i);
lstbOnlineClients.Dispatcher.Invoke(new Action<OnlineClientListBoxItem>((x) =>
{
lstbOnlineClients.Items.Add(x);
}), System.Windows.Threading.DispatcherPriority.Normal, item);
}
};
System.Threading.Thread mainThread = new System.Threading.Thread(threadstartdelegate);
mainThread.SetApartmentState(System.Threading.ApartmentState.STA);
mainThread.Start();
and at this part lstbOnlineClients.Items.Add(x); it is giving me the following error "The calling thread cannot access this object because a different thread owns it." can anyone help me because this is the method in which you can invoce a control's method from another thread. Any ideas?
Thank you in advance
|
|
|
|
|
This is the most general issue. You can access UI objects only from UI thread.
In WPF the UI thread is pointed using Dispatcher object. So you can replace the code
lstbOnlineClients.Items.Add(x);
with
this.Dispatcher.Invoke(DispatcherPriority.Normal, new System.Windows.Forms.MethodInvoker(delegate()<br />
{<br />
lstbOnlineClients.Items.Add(x);<br />
}));<br />
Dispatcher will invoke the code in the UI thread.
I hope this will help you.
Abhishek Sur
Don't forget to click "Good Answer" if you like this Solution. Visit My Website-->www.abhisheksur.com
|
|
|
|
|
The OP already uses Dispather.Invoke.
|
|
|
|
|
Add a 'faked' item to a ListBox which serves as an "Add New Item" button.
The listbox is bound to an SQL database via Linq2Sq. I'd like to see sth like this:
- Apple
- Orange
- Banana
- (add a new fruit)
When users selects (add a new fruit), then it becomes an empty TextBox in which user can input data of a new item. On lost focus (or immediately, whatever), another "faked" item appears.
How can I achieve this?
Thanks
Greetings - Jacek
|
|
|
|
|
Add the PK of each item to the item's tag. Add the "(add a new fruit)" item with a tag of -1.
In the change, check for -1.
Everything makes sense in someone's mind
|
|
|
|
|
Do you mean that I should store the "(add a new fruit)" item in the DB? If then, how to prevent WPF from updating that row in the DB when user is actually overwriting it with a "mango" or whatever? Everything is done with data-binding, so I do not have much control, I do not add items manually...
Greetings - Jacek
|
|
|
|
|
No, return a dataset of items from the database. Then add a new row to the bottom that has the "(add a new fruit)" and -1 for a key.
Before update, remove the row.
Everything makes sense in someone's mind
|
|
|
|