|
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
|
|
|
|
|
Jacek - off the top of my head, I'd be tempted to use a CompositeCollection[^] in the ListBox ItemsSource . Inside this CompositeCollection , I'd have an observable collection of fruit, a separate entry for the (add a new fruit) and a separate entry for the textbox. The last two entries would be datatriggered so that only one was visible at a time (based on the logic of selecting to add a fruit). When you add a new fruit, the (add a new fruit) option moves down the list.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I have created my story board using expression blend but when i run the control it will run only once.but i need continues animation pls let me know wht i am suppose to do???
Reasons are not Important but Results are Important.
http://www.sql4professional.blogspot.com
Swati Tripathi
|
|
|
|
|
|
thanks it works...
Reasons are not Important but Results are Important.
http://www.sql4professional.blogspot.com
Swati Tripathi
|
|
|
|
|
I have the following XAML (there's actually more, but I thought it wouldn't be helpful since it's all the same only for different columns):
<ListView x:Name="InnerListView"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
x:FieldModifier="public"
BorderBrush="Black" BorderThickness="1"
ItemsSource="{Binding}" >
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Downloads" />
</GridView>
</ListView.View>
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel >
<Grid DockPanel.Dock="Right" >
<Label Grid.Column="1" Content="{Binding Path=WpfDownloads}" />
</Grid>
and in the code, I'm setting the list views data context to the observable collection of objects I'm trying to display:
InnerListView.DataContext = myList;
However, when the listview is displayed, all of the columns show "Namespace.Object".
What am I doing wrong?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Is the path absolutely correct? It looks like you should be looking at a subproperty here, e.g. WpfDownloads.DownloadName. Without seeing the underlying code, I can't comment any further.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
WpfDownloads is a property of the object (derived from INotifyPropertyChanged ) contained in the observable collection. The set part of the property is being called, but the get isn't.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Yes, it's a property of the object, but what type is it? Is it a class in its own right? If so, you need to bind to a property in the instance of WpfDownloads (or you need to write a converter).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|