|
There is no such thing as a Name property for either a ModelVisual3D or a Model3DGroup when using it in the code-behind. It's the first thing I tried
|
|
|
|
|
There isn't an x:Name property?
|
|
|
|
|
x:Name is a dependency property - hence, you can set it in code using SetValue(this3DObject, "ObjectName"); (and use GetValue("ObjectName") as ModelVisual3D; to retrieve it).
"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 tried your code, but I'm not quite sure how to implement it. I'm very new to WPF. Let me give you a sample of the code I'm using. I use an array of ModelVisual3D's called mv3dCube, each array index holding a cube.
So each time I add a new cube I set the Content property of the ModelVisual3D to an item in a Model3DGroup array as follows:
mv3DCube[index].Content = mdl3DGrpCube[index];
But before I set the Content property, I want to assign name to the ModelVisual3D.
Can you please show me exactly how I would implement this using my code.
I tried something like the following:
mv3DCube[index].SetValue(this.mv3DCube[index], "someName") but it still gives me an error
|
|
|
|
|
I got it working.
I used ModelVisual3D.SetValue(FrameworkElement.NameProperty, "someName") and ModelVisual3D.GetValue(FrameworkElement.NameProperty)
Thanks guys
|
|
|
|
|
I can't get it working. I'd like to set/get a name from a dynamically loaded xaml file.
When I save the Viewport3D with this method, the name of the Viewport (specified in xaml) is written, but the name of my model isn't. Anyone has a solution?
using (FileStream stream = new FileStream("text.xaml", FileMode.Create, FileAccess.Write))
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.ConformanceLevel = ConformanceLevel.Auto;
XmlWriter writer = XmlWriter.Create(stream, settings);
XamlDesignerSerializationManager manager = new XamlDesignerSerializationManager(writer);
manager.XamlWriterMode = XamlWriterMode.Expression;
XamlWriter.Save(Viewport, manager);
}
-----------------
ModelVisual3D model = new ModelVisual3D();
model.Content = new GeometryModel3D(MeshPrimitives.Box(10, 10, 10), new DiffuseMaterial(new SolidColorBrush(Colors.Red)));
model.Transform = new TranslateTransform3D(new Vector3D(0, 20, 0));
model.SetValue(FrameworkElement.NameProperty, "SomeBox");
Viewport.Children.Add(model);
|
|
|
|
|
Your method won't work because you're setting the model's name programmatically in your code and not in the xaml. I think it will only write to xml whatever is explicitly defined in the xaml.
Can't you rather create this model as a resource in the xaml and then just reference that resource wherever you want to use it? That way you can give the resource a name and then this name should appear in the xml file.
|
|
|
|
|
You could try NameScope.RegisterName, looking at the docs there is also FrameworkElement.RegisterName but I'm not sure if either works with Visual3Ds.
|
|
|
|
|
Hello!
Imagine you have a view with his ViewModel. You have your commands created on that ViewModel and you can use it in the view using something like "{Binding MyCommand}". That is because the View's DataContext is the ViewModel.
But... Imagine now that you have a ItemsControl with a ObservableCollection of some class (like dog). You defined an ItemTemplate and inside, a DataTemplate. Well, every row is a dog item of that list. Now, you want a button in every row that delete that row. You have a command in the ViewModel that delete that dog but... How can you link the button with the command? The button datacontext is the Dog itself and not the ViewModel. You can't link to the command... Then, what is the correct solution to this kind of problem?
Thank you.
|
|
|
|
|
|
So i`ve found that it`s a bug in Windows XP.
Some people say that it`s needed to install 32-bit framework on 64-bit OS.Nonsense.Seems impossible.
So any other ways to make it play video?
|
|
|
|
|
Media Element will not work if WMP10 is not installed, have you checked that ?
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
C# WPF
I have this lines of code.
mediaElement.Source = new Uri(fileName, UriKind.Absolute);
mediaElement.Play();
Sometimes mediaElement plays the file (mp3 or video)... and sometimes will play that file after a while (3 minutes ++ like the file that just was played previously)
I tried that to put mediaElement.Stop(); or to stop the graph (like in directShow) but no results...
Please... please someone know why this lag?
|
|
|
|
|
How to create the WPF Web browser application, in which user can navigate through multiple pages?
|
|
|
|
|
As you're using WPF, you will need XAML, as well as some code.
Seriously, what have you tried ?
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Tell me how can i do that?
|
|
|
|
|
I assume you're joking ? What was the point of your original post ?
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
|
thank UUUU
|
|
|
|
|
Hi,
I am working on WPF. In this I will dynamically add images to a stack panel. During this process when I select an element and click a button, then the another image which is same as the selected element should be added.
That is I have to copy the selected UI element in another UIElelement and then I have to add this new UIElelment to the Stack panel. For this I wrote code like this:
UIElement DuplicateImg = selectedElement;
spanel.Children.Insert(GetSlideIndexinStackPanel(selectedElement), DuplicateImg);
but for this I am getting an error
"Additional information: Specified Visual is already a child of another Visual or the root of a CompositionTarget."
If anyone have any idea to solve this please reply me
Thanks in advance
|
|
|
|
|
|
Can't you just create a new Image object, and then use the same source as the original?
"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." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I have a wpf window containing a Tabcontol with 2 tab items. Both tab items contain a datagrid and some additional buttons and textboxes. I can't seem to find an event for the tab control that only fires when you select the tab item at the top. SelectionChanged fires for any item that I select in the tab item. I need my datagrid to bind to a new datatable whenever its host tab is selected. Please Help!
|
|
|
|
|
A few days ago JSOP mentioned something like this. Look here[^]
|
|
|
|
|
I created a new TabItem class, like so:
public class UDPTabItem : TabItem
{
public bool IsActive { get; set; }
public static readonly RoutedEvent ActivateEvent = EventManager.RegisterRoutedEvent("Activate",
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UDPTabItem));
public event RoutedEventHandler Activate
{
add { AddHandler(ActivateEvent, value); }
remove { RemoveHandler(ActivateEvent, value); }
}
private void RaiseActivateEvent()
{
RoutedEventArgs eventArgs = new RoutedEventArgs(UDPTabItem.ActivateEvent);
RaiseEvent(eventArgs);
}
public static readonly RoutedEvent DeactivateEvent = EventManager.RegisterRoutedEvent("Deactivate",
RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UDPTabItem));
public event RoutedEventHandler Deactivate
{
add { AddHandler(DeactivateEvent, value); }
remove { RemoveHandler(DeactivateEvent, value); }
}
private void RaiseDeactivateEvent()
{
RoutedEventArgs eventArgs = new RoutedEventArgs(UDPTabItem.DeactivateEvent);
RaiseEvent(eventArgs);
}
public UDPTabItem()
{
this.IsActive = false;
}
public void ActivateTab(bool activate)
{
IsActive = activate;
if (this.IsActive)
{
RaiseActivateEvent();
}
else
{
RaiseDeactivateEvent();
}
}
protected override void OnSelected(RoutedEventArgs e)
{
ActivateTab(true);
base.OnSelected(e);
}
protected override void OnUnselected(RoutedEventArgs e)
{
ActivateTab(false);
base.OnUnselected(e);
}
}
You may need to massage it since I had to cut out some stuff for use here.
"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." - Jason Jystad, 10/26/2001
|
|
|
|