|
|
Hi;
I'm new to WPF, and I'm trying to understand the underlying architecture, so please correct me if I'm wrong:
As far as I know, there are three possibilities to dynamically transform a GeometryModel3D during runtime:
a) Set the model's Transform-property to a Transform3DGroup once, to which you add new / duplicate Transformations.
b) Cast the model's Transform-property as a MatrixTransform3D and multiply its matrix with the Value-property of a Transformation (which i guess is pretty much case (a) )
c) Leave the Transform-property as a identity matrix and instead transform the model's Geometry.Positions property directly (provided you use a MeshGeometry3D) like such:
int i;
MeshGeometry3D mesh;
mesh = (_SomeModel.Geometry as MeshGeometry3D);
for (i = 0; i < mesh.Positions.Count; i++)
{
mesh.Positions[i] = _SomeTransform.Transform(
mesh.Positions[i]);
}
On first glance, option (c) seems like the best (though not most intuitive) choice, especially when you need the actual positions of the model(s); for example to calculate hit-detection.
Is there another way to easily access a model's current, transformed position(s)? And why does WPF transform a model's own space instead of just the actual coordinates?
Kind regards, Frank
|
|
|
|
|
I don't think (c) seems like the best option, although there are some scenarious where it might be appropriate to transform each vertex (or "position") directly...
The Transform property is there for a reason. You can move, rotate, scale etc. the entire model by setting just one matrix. That's far easier than transforming each vertex.
There is also a good reasony why WPF stores the positions relative to the model's coordinate system. This is actually how almost every CAD program and 3D engine works. Most of the time when you are editing the shape of a model you don't really care how the model is oriented and transformed, because you only pay attention to the shape itself, that's why relative coordinates are useful. You can always get the global coordinates easily by using the model's transformation matrix.
One more thing: moving each vertex of the model might be a lot slower than transforming the whole model at once. It depends on the implementation of the 3D engine, but if you set the Transform property of the model, the transformation of all vertices might be hardware accelerated, while transforming each vertex individually will definitely run on the CPU.
I can't answer your question ("which method is the best") because it depends on your application... But I would try to avoid option (c).
|
|
|
|
|
Hi we are working with WPF ribbon control.....
But finding some problem with it...Like Ribbon Application Menu if we want to remove it using XAML code den we r not able to do dat...
|
|
|
|
|
Your question is not very clear.
Maybe posting some code here can help!
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.
|
|
|
|
|
Any idea how to do this? Auto completing multiple values separated by comma into a single autocompletebox. Something similar to gmail to/cc/bcc address textbox.
|
|
|
|
|
You might want to inherit the existing AutoCompleteBox control and right your own one.
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'm trying to create a custom control that behaves like an horizontal StackPanel that hosts hyperlinks (with rich ToolTip).
A major difference is that I want to have horizontal scrollbar and keep the size of the control as one line of text.
I did it by inherit from ListBox and set my own Template, ItemsPanel and ItemTemplate.
It worked fine when I did all the work in my test WPF application, but when I moved the code to a class library, like it should be, I have a problem with the scrollbar.
When the width of the control if too short, a scrollbar thumb apears (I deleted it in my control!) and hides my links.
Also, I can not click the links or see the ToolTips because when the mouse is over the control the scrollbar takes control.
It is hard to show code here because then I would need to show all the Generic.xaml, instead I uploaded the whole solution (very small):
Code Here
How do I cancel this behavior?
Thanks,
Yariv
|
|
|
|
|
Solved. It was a problem of hidden VisualState (MouseOver).
I just copied the default ScrollBar style from the MSDN (instead of using the template the Expression created for me), then edited what I want and...it works.
Thanks
|
|
|
|
|
Thanks for posting the solution 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 created new ResourceDictionary - This Resource is actually a button.
I want to add some behavior to this button => in case the user will press on the button then the button will
stay in "press" state until the user will "press" it again ( something like Caps Lock ) and i don't know how to do it.
I have on my code Trigger that will call and change the button color to 'red' color in case the user press on it - but the color will be 'blue' again ( the original color ) when the user stop pressing on the button.
How can i do it ?
Thanks for The help.
|
|
|
|
|
There is a control called ToggleButton that does exactly what you need.
|
|
|
|
|
Hi
I have a very basic WPF question. Please forgive my
ignorance.
I have Visual Studio Solution with two VB Projects:
Project A is a WPF program that contains x, x being an ObservableCollection(of Rec) where rec is a Class of some database record.
Project B is a UserControl uc, containing, amongst other things a ListBox lb. The problem is how to display the x items in lb. Project A contains several instances of uc.
Possible solution 1:
Is there a way that I can bind lb directly to x? I seem to be unable to do so.
Possible solution 2:
Should I define a dependency property of ObservableCollection(of Rec) in B and give that a value in the Xaml of the uc instances. This also fails! Conceptually, this method has me worried, because I cannot see how uc obtains the rec info for formatting the records
in its DataTemplate. I have to define the Property as a ObservableCollection(of Object) to get past the compiler!
Possible solution 3.
It cannot be done!
BTW, I know enough to display x in a listbox defined in A quite nicely with a DataTemplate.
I have searched Google long and hard without finding anything that throws light on my dilemma! Any insight will be much appreciated.
David
|
|
|
|
|
Hey David,
Working with listbox is very easy.
You put the object in Resource, say your class which has the ObservableCollection is in X.
class X
{
public ObservableCollection<MyObject> { get;set;} ....
}
in XAML
<Window.Resources>
<local:X x:Key="mycollection" />
</Window.Resources>
<ListBox DataContext="{StaticResource mycollection}" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding MyText}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
So here the property MyText will be displayed in the list of MyObject .
You can also use ICollectionView to do this if you wish. Check my article on it :
http://www.abhisheksur.com/2010/08/woring-with-icollectionviewsource-in.html[^]
Abhishek Sur
Don't forget to click "Good Answer" if you like this Solution. Visit My Website-->www.abhisheksur.com
|
|
|
|
|
I have a question:
How to get client rectangle of a WPF window? I have tried using windows API GetClientRect, but it does not work and always return left=0, top=0.
I'm very appreciated if you can help me.
Thanks,
huy
|
|
|
|
|
One way to do it is to use VisualTreeHelper.GetDescendantBounds on the root element in the window.
|
|
|
|
|
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?
|
|
|
|