|
Hi ,
I need to acheive List View Scrolling with MVVM. As iam new to MVVM Can u please let me know how it can be acheived . Can anyone please provide a sample for the same if possible.
Thanks
Krish
|
|
|
|
|
Listview scrolling in general has nothing to do with MVVM and is an inherent property of the control.
Could you please give more details so we can understand your question better?
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.
|
|
|
|
|
I need to scroll the listview on a button click. Iam following MVVM pattern. I tried the following but it is not working.
<local:SortableListView x:Name="headLinesGridView" IsSynchronizedWithCurrentItem="True" Style="{DynamicResource ListViewStyle}" ScrollViewer.VerticalScrollBarVisibility="Hidden"<br />
ItemsSource="{Binding Source={StaticResource TestDataSource}}" ItemContainerStyle="{StaticResource headLinesGridViewStyle}"<br />
ColumnHeaderSortedAscendingTemplate="HeaderTemplateArrowUp" ColumnHeaderSortedDescendingTemplate="HeaderTemplateArrowDown" ColumnHeaderNotSortedTemplate="HeaderTemplateTransparent"><br />
<ListView.View> <br />
<GridView ColumnHeaderContainerStyle="{StaticResource gridViewHeaderStyle}" ColumnHeaderTemplate="{StaticResource HeaderTemplateTransparent}"><br />
<local:SortableGridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" SortPropertyName="ID" Width="50" /><br />
<local:SortableGridViewColumn Header="First Name" DisplayMemberBinding="{Binding FirstName}" SortPropertyName="FirstName" IsDefaultSortColumn="True"/><br />
<local:SortableGridViewColumn Header="Last Name" DisplayMemberBinding="{Binding LastName}" SortPropertyName="LastName" /><br />
<local:SortableGridViewColumn Header="Date of Birth" DisplayMemberBinding="{Binding DateOfBirth}" SortPropertyName="DateOfBirth" /><br />
<local:SortableGridViewColumn Header="QueueStatus" SortPropertyName="QueueStatus" IsDefaultSortColumn="True" CellTemplate="{StaticResource IconCellTemplate}"/><br />
</GridView> <br />
</ListView.View><br />
<ListView.ItemsPanel><br />
<ItemsPanelTemplate><br />
<WrapPanel Orientation="Vertical"></WrapPanel><br />
</ItemsPanelTemplate><br />
</ListView.ItemsPanel><br />
</local:SortableListView> <br />
<Button Grid.Row="1" Command="ScrollBar.LineDownCommand" CommandTarget="{Binding ElementName = Test}">Scroll Down</Button>
|
|
|
|
|
This is a common mistake in MVVM, trying to do too much in the VM. As this line down operation has absolutely no bearing on the model, it's perfectly fine to do this in code behind the view; after all, you just want to move the scrollbar on a visual. Go for it.
|
|
|
|
|
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.
|
|
|
|
|
Hey,
is there anyone how get experiences with this class. I try to use it, in a normal way like this:
ManagementObjectSearcher mang = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject obj in mang.Get())
{
MessageBox.Show(Convert.ToString(obj["Description"]));
}
Here, i used the DiskDrive-Class, and all work fine, but if i try to use the PhysicalMediaClass in the equal way, the output just gives me a zero-string.
what´s my mistake?? can anyone help me???
holzmcgyver
|
|
|
|
|
holzmcgyver wrote: what´s my mistake??
Well, for a start, this is the Silverlight/WPF forum.
holzmcgyver wrote: MessageBox.Show(Convert.ToString(obj["Description"]));
Does Description exist in the collection? Try Tag instead.
|
|
|
|
|
I recently started the WPF and I came across a weird behavior in listboxes.
I have it binding to a viewmodel object and displaying the view properly, even have it selecting the item properly.
Sometimes those listbox have text boxes for my user to type in, and when they hit the F key, it moves to the next listbox item.
After alot of digging I found out that it has to do with the name space of the item bound to the listbox. If I change the viewmodels class to "zsomename.folder.viewmodel" then when I type z in the text box it moves it to the next listbox item.
Its like there's a built in behavior to select a matching listbox item base off the starting letter... but how do I remove this, or what is calling this.
Anyone have any ideas?
|
|
|
|
|
That sounds weird. Can you paste a small code example here so we can reproduce this?
|
|
|
|
|
There is indeed built in behaviour to do this - however, your textbox shouldn't invoke this, are you using a datatemplate?
Can you please post the XAML that creates the listbox and its items? I'm sure we can help out
By the way the zsomename.folder.viewmodel is indeed why Z is selecting an item, however, if the keydown event in the textbox is bubbling then this needs to be address (bubbling events are those that at a point in the logical tree and move up).
|
|
|
|
|
Well it came up because we have a list box inside a listbox.
I was trying to make it so that when the user presses a letter "a,b,c,d,e,f... etc" it would select that given listbox subitem. Instead it move to the next question.
So this is happening in the key down event and I need to handle it there? Or is there a better way of doing it?
|
|
|
|
|
I think what you are looking for is TemplateBinding . See here[^].
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.
|
|
|
|
|
Hi
I want to generate decimal point automatically while entering in textbox of wpf. Like the decimal point automatically generated while entering amount in ATM machine.
Please help thanks in advance.
|
|
|
|
|
Handle the focus lost event, then take the text of the textbox, and make sure it's a number, then use the Substring function to split it and insert your decimal.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You could use a masked edit box.
See here[^].
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.
|
|
|
|
|
But these are paid ones how can I implement these in my wpf window application
|
|
|
|
|
|
You can add normal winforms controls (like maskedtextbox) to WPF.
From: Wrox, WPF Programmer’s Reference.
Before you can use a WindowsFormsHost, you must perform three steps:
1. Add a reference to the WindowsFormsIntegration library. In Visual Studio, you can open the
Project menu, select “Add Reference,” and select the library from the .NET tab on the Add
Reference dialog. In Expression Blend, you can open the Project menu, select Add Reference,
and then browse to the library file. On my system, it’s installed at C:\Program Files\
Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll.
2. Add a reference to the System.Windows.Forms.dll library. Again, in Visual Studio, you can
use the Project menu’s Add Reference command and select the library from the resulting dialog.
In Expression Blend, you can again use the Project menu’s Add Reference command and
then browse to the library file. On my system, it’s installed at C:\Windows\Microsoft.NET\
Framework\v2.0.50727\System.Windows.Forms.dll.
3. Add a namespace declaration for the Windows Forms namespace to the top of the XAML
file. The declaration should look something like this:
xmlns:wf=”clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms”
Hope this helps.
V.
|
|
|
|
|
Be aware, though, that any theming you apply to your textboxes will not apply. Also, focus management in WPF is problematic enough without adding Winforms into the mix. I'd avoid this option altogether and use a native WPF version instead as there are plenty of freely available solutions and this is an unnecessary step.
|
|
|
|
|
MM didn't know that. Thanks, I'll keep that in mind.
V.
|
|
|
|
|
I have a custom control, called 'YesNoButton'. It's two buttons, one says yes, one says no. I have a property, 'IsYes'. I'd like to bind to that property from my preferences class, so that I don't have to write any code to tie the two. Here's what I have:
<ctl:YesNoButton x:Name="showProgessOnDesktop" IsYes="{Binding Mode=TwoWay, Path=ShowOnDesktop, Source={x:Static c:Preferences.Instance}}"/>
is my XAML with my attempted binding. The code in the control is as follows ( created with help from the tab/tab auto generate thing )
public bool IsYes
{
get { return (bool)GetValue(IsYesProperty); }
set
{
SetValue(IsYesProperty, value);
no.Foreground = (value) ? Brushes.LightGray : Brushes.Black;
yes.Foreground = (value) ? Brushes.Black : Brushes.LightGray;
}
}
public static readonly DependencyProperty IsYesProperty =
DependencyProperty.Register("IsYes", typeof(bool), typeof(YesNoButton), new UIPropertyMetadata(false));
This code compiles and runs, so I assume that my binding is where the issue is. Preferences is a static class, with Instance as a static variable. If I set it in code, it works, internally, but does not change the UI on this form. If I set the default of the dependency property to 'true' it doesn't change the UI. If I set breakpoints, my setter is called when the value is set in code, and the values in the preferences class get set. My issue is entirely that I can't get the control to call the right getter on the preferences class to set itself up initially, that is, it always shows the same value and does not respect the value in the prefs class.
OK, I got it. I had to wait for the Loaded event, THEN I had to access the property to force it to read from the source, which then ran the code to set the state of the UI. If there's any way to make it read automatically, I'd love to know it.
Thanks for any help.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
modified on Thursday, September 2, 2010 2:04 AM
|
|
|
|
|
Hi Christian Graus,
Included UpdateSourceTrigger="PropertyChanged" in binding. Like,
"showProgessOnDesktop" IsYes="{Binding Mode=TwoWay, Path=ShowOnDesktop, Source={x:Static c:Preferences.Instance}, UpdateSourceTrigger=PropertyChanged}"
HTH
|
|
|
|
|
I have a WPF that I'm trying to track down a problem to.
Basically when I have a list box and the user hits the "F" key it moves "currentselection" to the next listbox item in the list box. (this is really bad when you have a use trying to type into a textbox and they use the letter "F" and it moves to the next listboxitem)
I'm looked at the InputManager and a few other classes but I'm not exactly sure how to figure out what is happening to change the selected item.
Anyone know of a good way of tracking this down?
|
|
|
|
|
Hi Experts,
I am little new to Command binding so this might be a trivial question to many. I know that we can add Command bindings in xaml of a window and give its correspondng property in viewmodel. This viewmodel will be given to the DataContext of the window. Something like the following
--app.xaml.cs
mainWindow.DataContext = viewModel;
-- xaml
lt;Button Grid.Row="1" HorizontalAlignment="Right" Margin="0,3,18,3" Name="button1" Width="110"
Command="{Binding LoadCommand}">_Load</Button>
-- viewmodel
public ICommand LoadCommand
{
get
{
if (m_LoadCommand == null)
{
m_LoadCommand = new RelayCommand(param => CanLoad(), param => Load());
}
return m_LoadCommand;
}
}
Here the relaycommand is a class which implements ICommand interface. CanLoad() and Load() are the methods which will get executed for canexecute and execute action of the relaycommand respectively. This is the click event of the button which is handled.
I have a user control which has a custom routedevent registered in it and the user control is then used on a window. I am currently adding the event handler explicitly in code.
this.ucCustomEvent1.CustomClick += new RoutedEventHandler(ucCustomEvent_CustomClick);
this.AddHandler(UserControlThatCreatesEvent.CustomClickEvent, new RoutedEventHandler(ucCustomEvent_CustomClick));
I dont want to hook up the routedevent explicitly in code but in the xaml in the similar way as in the button example. I have uploaded the working sample code here for your perusal.
Please help!
Thanks in advance!
Regards,
Samar
|
|
|
|
|
Hi All,
I am able to solve this problem of mine. The link given here explain it. Just to keep it brief i did it using something similar to the following lines of code.
<c:MyUserControl local:CommandBehavior.RoutedEventName="MyCustomClick"
local:CommandBehavior.TheCommandToRun="{Binding MyViewModelCommand}"/>
CommandBehavior is a class given in the link above.
Thanks everyone for giving in your valuable time.
Regards,
Samar
|
|
|
|