|
Lookup the ValueConverter object.
.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
|
|
|
|
|
I am having an issue binding a command to a user control. My main window calls a workspace viewmodel that supplies data via observable collection to a datagrid in the workspace viewmodel. In this datagrid I put a button, but am having an issue figuring out how to bind a command to it.
The datagrid itemssource is an observable collection from a viewmodel. I have a command on that same view model that tells the datagrid what to do when a button field is pressed. I bound to that name but it isn't working because. I am guessing this is because the datagrid (Which is on a user control) is bound to the observable collection of data and the command is outside the scope of that collection.
So on what viewmodel do I put my command in order to execute it on my usercontrol and how to I reference it on my user control?
Sorry for the vagueness of it all, this is a bit difficult to explain.
Cheers, --EA
|
|
|
|
|
After reading your convoluted question I can sympathise completely.
I think, your ITEMSOURCE for the datagrid is the collection, your DATACONTEXT of the control is where the command should reside. This stuff is completely different from what I am used to!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you use datagrid and you want a command inside the datagrid, then you should define that command in the ObservableCollection item object.
eg, If you use ObservableCollection<Customer> as ItemsSource, define the command in Customer class.
|
|
|
|
|
I had considered that as well, but the class is an entity created by the entity framework directly from an SQL table and I thought that overriding that class to add a command would be a little bit more spaghetti than I wanted to deal with. Still, that seems to me like the best working solution. Thank you for the advice.
Cheers, --EA
|
|
|
|
|
One way I have found to solve this is to bind your command to the parent datasource in the xaml.
For e.g.
cmd:mycommand="{Binding ElementName=LayoutRoot, Path=DataContext.RevertClick}" .
LayoutRoot is what would be the main layout grid in the xaml (added by default)....but you could have used a different name.
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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Are the columns auto-generated?
|
|
|
|
|
Not auto generated. The answer was to reference the command on the viewmodel using relativesource - findancestor. Nice and easy.
Thanks for the help.
|
|
|
|
|
Sounds like you want:
- DockPanel
-- Toolbar (Docked to the top)
-- Progress Bar (Docked to the bottom)
-- Grid (No docking, so will take remaining space)
--- Column 0 (*-width, so takes up half)
---- Left panel
--- Column 1 (*-width)
---- Right panel
|
|
|
|
|
I have user control that i wrote.
this user control is appear on some Window ( host ) and the window size is dynamic.
I want to make the user control size to be also dynamic - and if the window host size is change ( grow / shrink ) then the user control also will change.
I try a lot of thinks - but the user control size is not changing ( also try to mark the user control as 'fill' and its not working. )
How to do it ?
Thanks
|
|
|
|
|
Things to check:
1) Does the container (The UserControl's parent) have its HorizontalContentAlignment and VerticalContentAlignment set to Stretch?
2) Does the UserControl have its HorizontalAlignment and VerticalAlignment set to Stretch?
3) Are you sure the UserControl isn't already stretching? Set its background to an obvious color. Maybe the stuff INSIDE your control isn't resizing.
|
|
|
|
|
Hi,
I have a query that returns a lot of records. What I have done to optimize the initial data bind when setting ItemsSource is to only show the first 100 records.
However, I allow users to gain access to the remaining records by indicating there are more records and if they press a button, all the records are bound to the DataGrid. This setting of ItemsSource takes 10-15 seconds.
I don't mind how long that takes, but I have a storyboard animation that I overlay to let the user know something is happening. This animation is fine whilst querying and binding 100 records (must be quick), but when binding 1000+ records, the animation doesn't run.
I'm presuming this is because the binding and the animation are on the UI dispatcher thread, but this is kind of defeating my ability to keep the user in the loop in what is going on.
Has anyone solved this issue, either by doing it right (am I doing something wrong?) or by doing it another way?
Thanks for any advice.
Simon
|
|
|
|
|
<code><pre>
Public WithEvents hyperLink As New Hyperlink()
~~~~~~~~~~~~~~~~~
For Each Lists As Status In Some.Status
TextBlock.Margin = New Thickness(4)
TextBlock.TextWrapping = TextWrapping.Wrap
hyperLink = New Hyperlink() With {.NavigateUri = New Uri("ok://" & Lists.Text)}
hyperLink.Inlines.Add("OK")
TextBlock.Inlines.Add(Lists.Text)
TextBlock.Inlines.Add(hyperLink)
Grid.SetColumn(TextBlock, 1)
Grid.SetRow(TextBlock, grdList.RowDefinitions.Count - 1)
grdList.Children.Add(TextBlock)
Next
Private Sub hyperLink_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles hyperLink.Click
MsgBox("Here I want to put a hyperlink address.")
End Sub
</pre></code>
The above code is the approximate.
Look at the relevant section in the code above hyperlink, add a hyperlink to the Grid can be found.
Yeah, but added to the first hypertext link event occurs.
Only first hyperlink.
What should I do all the hyperlinks that event occurs?
|
|
|
|
|
rus204 wrote: TextBlock.Margin = New Thickness(4)
I am not sure that I understand your question but when you run this loop, you only add the hyperlink to one textblock. So only the first event fires.
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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Is there a decent way?
TextBlock.Margin = New Thickness(4) is margin is too narrow to declare.
|
|
|
|
|
rus204 wrote:
Yeah, but added to the first hypertext link event occurs.
Only first hyperlink.
How do you attach hyperLink_Click to click event?
|
|
|
|
|
I was declared hyperlink as WithEvents.
So I can add a Click event.
|
|
|
|
|
Your english is quite poor or i do not understand what you want to ask.
You said First Hyperling, do you mean it will fire event when you click firt hyperling on list, or does it fire once where you click any hyperlings on list?
I think it is a second. As again, How do you asign Click event? Your answer was not good enough. I am C# developer.
are you using System.Windows.Documents.HyperLink from PresentationFramework.dll? if so do you aware that each hyperling has its own click event?
|
|
|
|
|
second you think is right.
and.. I'm not using PresentationFramework.dll
(I'm not one English-speaking countries. So I do not speak English very well. Sorry)
|
|
|
|
|
there is a possiblity you need to move event decleration (xaml) on a logic list or force a focus to element
|
|
|
|
|
What does that mean?
Some do not understand.
|
|
|
|
|
Can you paste a XAML sample, where it contains grdList and event hyperLink_Click. Not a code
For setting focus, you can use:
grdList.SetFocus();
This example is in C#. Veary easy to convert to VB.NET. But i do not know Syntax for vb.net
|
|
|
|
|
Ah! I've solved this problem.
Thank You!
|
|
|
|
|
How can I tell whether a Silverlight Textbox vertical scrollbar is visible or not?
When the text is short the scrollbar is hidden. When the text is long it's shown. Is there a means to check if the vertical scrollbar is visible?
Thanks in advance,
marcelo
|
|
|
|
|
Try putting this code in the textBox.Loaded event handler:
ScrollBar verticalScrollBar = ((FrameworkElement)VisualTreeHelper.GetChild(viewer, 0)).FindName("VerticalScrollBar") as ScrollBar;
verticalScrollBar.ValueChanged += (s, ev) => button.Visibility = System.Windows.Visibility.Collapsed;
I got his code from here (google is your friend, btw):
http://www.c-sharpcorner.com/Blogs/BlogDetail.aspx?BlogId=3703[^]
.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
|
|
|
|