|
Hi Karl,
Yes, I want to create my own language service with Syntax Highlighting and Intellisense. I want to create a usercontrol something like text box. Is this possible?
Thanks,
Charith Jayasundara
|
|
|
|
|
Charith,
I'm sorry but writing a Language Service is something I have no knowledge about.
Can I suggest posting your question on the MSDN Visual Studio forum. This will give your question the attention it needs.
If you don't get a reply there in a few days, reply to this message and I'll get you the help. If you need to reply, plesae give me the link to your question on the form.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
I'm new to WPF. I'm trying to create an application that displays 3 images stacked on top of one another. The images shall be zoomable and rotateable just like in 3D. I wonder how to achieve this.
What I have done is I have created 3 mesh surfaces stacked on top of one another in 3D using Viewport3D and GeometryModel3D. It's based on a sample program I got from the internet. I haven't figured out how to paint images on the 3 surfaces.
For zooming and rotating, this code uses Transform3DGroup. It's working like a charm.
My final product will have to also have 3D markers scattered on the 3 images and when the user clicks on a marker, some tips shall be displayed. I'm not so concerned about this feature yet as it's a good to have, not must have. I need to get the foundation right first before adding this fancy feature.
Before I continue down this path, I wonder if I'm on the right track.
Any suggestions would be appreciated.
Here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Media3D;
namespace Wpf3DTest {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private GeometryModel3D mGeometry;
private bool mDown;
private Point mLastPos;
public MainWindow() {
InitializeComponent();
BuildSolid();
}
private void BuildSolid() {
// Define 3D mesh object
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions.Add(new Point3D(-1, -1, 1));
mesh.Positions.Add(new Point3D(1, -1, 1));
mesh.Positions.Add(new Point3D(-1, -1, -1));
mesh.Positions.Add(new Point3D(1, -1, -1));
mesh.Positions.Add(new Point3D(-1, 0, 1));
mesh.Positions.Add(new Point3D(1, 0, 1));
mesh.Positions.Add(new Point3D(-1, 0, -1));
mesh.Positions.Add(new Point3D(1, 0, -1));
mesh.Positions.Add(new Point3D(-1, 1, 1));
mesh.Positions.Add(new Point3D(1, 1, 1));
mesh.Positions.Add(new Point3D(-1, 1, -1));
mesh.Positions.Add(new Point3D(1, 1, -1));
//mesh.Positions.Add(new Point3D(-0.5, -0.5, 1));
//mesh.Normals.Add(new Vector3D(0, 0, 1));
//mesh.Positions.Add(new Point3D(0.5, -0.5, 1));
//mesh.Normals.Add(new Vector3D(0, 0, 1));
//mesh.Positions.Add(new Point3D(0.5, 0.5, 1));
//mesh.Normals.Add(new Vector3D(0, 0, 1));
//mesh.Positions.Add(new Point3D(-0.5, 0.5, 1));
//mesh.Normals.Add(new Vector3D(0, 0, 1));
//mesh.Positions.Add(new Point3D(-1, -1, -1));
//mesh.Normals.Add(new Vector3D(0, 0, -1));
//mesh.Positions.Add(new Point3D(1, -1, -1));
//mesh.Normals.Add(new Vector3D(0, 0, -1));
//mesh.Positions.Add(new Point3D(1, 1, -1));
//mesh.Normals.Add(new Vector3D(0, 0, -1));
//mesh.Positions.Add(new Point3D(-1, 1, -1));
//mesh.Normals.Add(new Vector3D(0, 0, -1));
//my code for the bottom face
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(7);
mesh.TriangleIndices.Add(7);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(8);
mesh.TriangleIndices.Add(9);
mesh.TriangleIndices.Add(11);
mesh.TriangleIndices.Add(11);
mesh.TriangleIndices.Add(10);
mesh.TriangleIndices.Add(8);
/*
// Front face
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(0);
// Back face
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(7);
mesh.TriangleIndices.Add(6);
// Right face
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(2);
// Top face
mesh.TriangleIndices.Add(2);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(6);
mesh.TriangleIndices.Add(7);
// Bottom face
mesh.TriangleIndices.Add(5);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(5);
// Right face
mesh.TriangleIndices.Add(4);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(3);
mesh.TriangleIndices.Add(7);
mesh.TriangleIndices.Add(4);
*/
// Geometry creation
mGeometry = new GeometryModel3D(mesh, new DiffuseMaterial(Brushes.YellowGreen));
mGeometry.Transform = new Transform3DGroup();
group.Children.Add(mGeometry);
}
private void Grid_MouseWheel(object sender, MouseWheelEventArgs e) {
camera.Position = new Point3D(camera.Position.X, camera.Position.Y, camera.Position.Z - e.Delta / 250D);
}
private void Button_Click(object sender, RoutedEventArgs e) {
camera.Position = new Point3D(camera.Position.X, camera.Position.Y, 5);
mGeometry.Transform = new Transform3DGroup();
}
private void Grid_MouseMove(object sender, MouseEventArgs e) {
if(mDown) {
Point pos = Mouse.GetPosition(viewport);
Point actualPos = new Point(pos.X - viewport.ActualWidth / 2, viewport.ActualHeight / 2 - pos.Y);
double dx = actualPos.X - mLastPos.X, dy = actualPos.Y - mLastPos.Y;
double mouseAngle = 0;
if(dx != 0 && dy != 0) {
mouseAngle = Math.Asin(Math.Abs(dy) / Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)));
if(dx < 0 && dy > 0) mouseAngle += Math.PI / 2;
else if(dx < 0 && dy < 0) mouseAngle += Math.PI;
else if(dx > 0 && dy < 0) mouseAngle += Math.PI * 1.5;
}
else if(dx == 0 && dy != 0) mouseAngle = Math.Sign(dy) > 0 ? Math.PI / 2 : Math.PI * 1.5;
else if(dx != 0 && dy == 0) mouseAngle = Math.Sign(dx) > 0 ? 0 : Math.PI;
double axisAngle = mouseAngle + Math.PI / 2;
Vector3D axis = new Vector3D(Math.Cos(axisAngle) * 4, Math.Sin(axisAngle) * 4, 0);
double rotation = 0.01 * Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
Transform3DGroup group = mGeometry.Transform as Transform3DGroup;
QuaternionRotation3D r = new QuaternionRotation3D(new Quaternion(axis, rotation * 180 / Math.PI));
group.Children.Add(new RotateTransform3D(r));
mLastPos = actualPos;
}
}
private void Grid_MouseDown(object sender, MouseButtonEventArgs e) {
if(e.LeftButton != MouseButtonState.Pressed) return;
mDown = true;
Point pos = Mouse.GetPosition(viewport);
mLastPos = new Point(pos.X - viewport.ActualWidth / 2, viewport.ActualHeight / 2 - pos.Y);
}
private void Grid_MouseUp(object sender, MouseButtonEventArgs e) {
mDown = false;
}
}
}
|
|
|
|
|
|
Hi all!
I've found lots of examples describing databinding, but still I haven't got a clue how to solve my problem. The frustrating thing is I think it is easy. But still, I'm lost...
In a WPF application, I invoke a WCF service call (contactClient.GetContacts()), which returns an array of Friend objects.
Window.xaml.cs:
private void PopulateContactsListBox()
{
listBoxContacts.Items.Clear();
listBoxContacts.ItemsSource = contactClient.GetContacts();
}
My intention is to let a listbox display the result returned from the WCF service call. And it does, but it doesn't display the actual data. Instead it displays the ToString() representation. In other words, the listbox displays the type returned by the service call; like "DataLayer.Friend".
So, how do I display the actual data from the service call in my listbox?
Thank you!
|
|
|
|
|
I'm not sure if this is the same in WPF, but in ASP.NET the databound controls have properties for you to set which property or field of the returned data items are used for 1) displaying text and 2) the actual value of the item. Perhaps WPF has something similar?
|
|
|
|
|
You need to set the items that you want to display. Typically it would look something like this:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Title}" />
<TextBlock Text="{Binding Path=Surname}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
|
|
|
|
|
Yeah, as Pete indicated you need a datatemplate as the listbox doesn't know how to display a Friend object so it just calls the ToString method.
You can move the datatemplate into a resource section. Such as Window.Resources or even Application.Resources. Another neat thing is if you set the DataType on the DataTemplate to your Friend object, it will be used automatically display it. Along the lines of this:
<datatemplate datatype="{x:Type local:Friend}">
....
|
|
|
|
|
Thank you guys! It worked with the datatemplate stuff.
Have a nice day
|
|
|
|
|
You're welcome, and you have a nice day too.
|
|
|
|
|
Well, this has taken some doing but I've released an update to MoXAML Power Toys[^] including a WPF App Wizard.
|
|
|
|
|
You and Karl ROCK!!
Thanks for sharing!
Cheers
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Gosh thanks Mark. Nah - you're right. We do ROCK.
|
|
|
|
|
Just keeping it real and fun!!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Greetings!
I have a class which derives from UIElement (I thought I keep it slim)
which has two DependencyProperties.
What I want to do is, that I can hook up to the event when one of those dp values changed.
Can't get it done because INotifyPropertyChanged does not allow the Implementation set static.
Background is, that when one of the n Melements changes it's PositionXValue, different Methods have to be called
class MElement :UIElement, INotifyPropertyChanged
{
public static readonly DependencyProperty PositionXProperty = DependencyProperty.Register(
"PositionX",
typeof(int),
typeof(MElement),
new FrameworkPropertyMetadata(
new PropertyChangedCallback(OnPositionChanged))
);
public int PositionX
{
get { return (int)this.GetValue(PositionXProperty); }
set { this.SetValue(PositionXProperty, value); }
}
public event PropertyChangedEventHandler PropertyChanged;
private static void OnPositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (PropertyChanged !=null)
{
}
}
}
Maybe I misunderstood the concept of this, but isn't this the way it was meant to be?
|
|
|
|
|
You don't need to use INotifyProperty changed when using dependency properties just add the logic in the OnPositionChanged handler. If you just want to call methods on MElement you cast d in OnPositionChanged. If you need to expose it to other classes you can raise the event/routed event in a similar way. There are snippets which create dependency properties with instance methods to use/override which are useful try Dr WPF's at http://drwpf.com/blog/Home/tabid/36/EntryId/22/Default.aspx
Use INotifyPropertyChanged with custom classes that don't derive from DependencyObject.
|
|
|
|
|
Thank you, am going to check out the snippets.
Difference DO and InotifyPropertyChanged is now understood.
Thanks again
|
|
|
|
|
Hi!
I have a UserControl with a list box which has a ItemTemplate.
Item template is also my own UserControl - "TemplateControl"
I'm trying to bind TemplateControl dependency property to a UserControl dependency property. So every instance of the TemplateControl in the list would change when I change the property in the UserControl.
The simplyfied source is like this.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="TestBlend.UserControl1"
x:Name="UserControl" >
<StackPanel>
<TextBlock Text="{Binding Path=MyProperty, ElementName=UserControl}" />
<ListBox ItemsSource="{Binding XPath=MyDataSource}" >
<ListBox.ItemTemplate>
<DataTemplate>
<TestBlend:TemplateControl Text="{Binding Path=MyProperty, ElementName=UserControl}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</UserControl>
The textbox Binding works fine, but binding in the TemplateControl does not work.
Does anyone have an idea how to solve or work around this problem?
Thank you all
<div class="ForumMod">modified on Friday, October 10, 2008 7:19 AM</div>
|
|
|
|
|
|
Actually It wasn't my idea.
After a bit of searching, I found out I have to go and read some books about Dependency Properties and the concept behind them, because there's something I figured wrong about the whole concept how they work
Thanks anyway
|
|
|
|
|
Do you still need help, resolving your issue?
If not, edit the question and let us know.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Well, the problem is still there.
But I found the main problem. The problem is that I started working with WPF one month ago so I still have much to learn
When I get to know it better, I'll probably find the answer, or at least I'll be able to ask the right question.
Thanks Carl
|
|
|
|
|
Been there!! Keep plugging away, you'll be SO glad you did!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
|
Awesome! I love meeting devlopers from all over the world.
"Plugging away" in that context is a phrase that means, keep working, keep going, keep coding, keep reading books, keep reading Internet articles.
It's normally used in a postive context also.
In other words, you are doing the correct thing and doing a great job!
modified 27-Feb-21 21:01pm.
|
|
|
|
|