Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

NaturalVideoWidth & NaturalVideoHeight in MediaUriElement of Wpfmediakit

$
0
0
Hi
 
Can you please help me how to get the videos NaturalVideoWidth and NaturalVideoHeight 
in MediaUriElement from WpfMediaKit. where default NaturalVideoWidth and NaturalVideoHeight in MediaUriElemt Always Return 0. 
 
Thank You

Wpf ListBox Hosting Windows Form Contols : Drawing Problem

$
0
0

Hi All,

I have a windows form image control(For Demonstration purpose, basically it is a WindowForm UserControl Hosting ActiveX Flash Player Control. ) inside  WFP - ListBox,

When i am scrolling Down and Up in ListBox. Windows form control is not Drawing correctly, it is going out of the ListBox..

XAML Code...

<Window x:Class="WPF_Demos.Window3"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:UC="clr-namespace:WPF_Demos"
        xmlns:win="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="Window3" Height="500" Width="500"><!-- Set the ItemTemplate of the ListBox to a DataTemplate which
                explains how to display an object of type BitmapImage. --><Window.Resources><Style TargetType="{x:Type ListBox}"><Setter Property="ItemTemplate"><Setter.Value><DataTemplate><StackPanel><WindowsFormsHost x:Name="winhost"><win:PictureBox x:Name="picbox"  Width="200" Height="200" SizeMode="StretchImage" ImageLocation="C:\DOTNET\WPF\WPF_Demos\WPF_Demos\Images\Desert.jpg"/></WindowsFormsHost></StackPanel></DataTemplate></Setter.Value></Setter><Setter Property="ItemsPanel"><Setter.Value><ItemsPanelTemplate><WrapPanel /></ItemsPanelTemplate></Setter.Value></Setter><Setter
                    Property="ScrollViewer.HorizontalScrollBarVisibility"
                    Value="Disabled"
                /></Style></Window.Resources><Grid><ListBox x:Name="lstImgs" ScrollBar.Scroll="lstImgs_Scroll" Margin="100"  ListBox.MouseDoubleClick="StackPanel_MouseDoubleClick" ItemsSource="{Binding }"/></Grid></Window>

C# Code:

 this.DataContext = System.Linq.Enumerable.Range(0, 30);

I have read lots of article 

http://bartwullems.blogspot.in/2010/11/wpf-and-winforms-airspace-problem.html

After reading this article i got to how to solve AirSpace Problem when u have single control. Not like ListBox hosting Multiple WindowsForm Control.

and I have read this forum thread ....

http://social.msdn.microsoft.com/forums/en-US/wpf/thread/1e1a9728-1b1b-4336-afe7-5513c1beb3cc

I want to know that how to solve this problem.

please help me...


Vikas Gupta

Do I need to learn Lync 2010, seems like Lync is going to implement the .NET 4.5.

RowDefinition.Height=Auto => ActualHeight = ?

Joining Open Source Projects

$
0
0

Good afternoon WPF Community,

my question for today is about joining/contributing to Open-Source-Projects (WPF).

Does somebody know about this kind of projects and have some links for me to look at.

All i want is:  to Join in as UI Designer and participate for 2 to 3 hours a day after work.

my goal is:    to get more practical knowledge and help others & get help from others, if needed.

Advices are welcome.

Regards

Stan

How to assign color for a bunch of buttons programatically

$
0
0

I got a grid of 5*5 with buttons (25 in total). I want to programatically assign background color for these and I want to know if there a way to do this instead of assigning one at a time like this:

btn1.Background = Color.Red;
btn2.Background = Color.Blue;
btn3.Background = Color.Green;
etc...

Can I somehow use a loop? 



how to enable a in xaml definable gridview from out of an usercontrolhey

$
0
0

hey,

i wanna create my own listview from bottom up and decide to create all inside a grid which is nested inside a customcontrol.

now  i wanna provide a collectionclass like gridview to enable the Definition from columns inside my customlistview via xaml.

Means, a user, implementing my customcontrol should be allowed to create columns in xaml.

I really dont know how to handle this Problem, which Attributes should i use???

filtering Xml live data

$
0
0

I have an aplication in wpf C#.

it have simple rss based news data.

How can i filter, saperat & asign data (that's in the discription )different controlls

Please point me in right direction.

thanks


bina


how to create nested child using dataset to create xml file?

$
0
0
i want to create structure like:

<Grid>
  <StackPanel>
    <Button>
       <TextBlock>Hello
       </TextBlock>
    </Button>
   </StackPanel>
</Grid>

    

for that i am creating  `DataTable` to define layout,`DataRow` to define elements and `DataColumn` to define attributes of elements.
  Can anyone give code for that.
  Thanks in advance.

-Akash Joshi

WPF Prevent an item being selectect in combobox when hovered

$
0
0

One of our QA noticed this combobox behavior that if they hover on the combobox items, it get selected. What they are expecting is this should not happen and it should only be selected when clicked.

To reproduce this problem. here's a simple XAML

<Grid><Grid.DataContext><local:CBItems/></Grid.DataContext><StackPanel VerticalAlignment="Center"><ComboBox IsEditable="True" ItemsSource="{Binding Items}" /></StackPanel></Grid>

and here's the test class

public class CBItems
{
	List<string> t = new List<string>()
	{"item 1","item 2","item 3","item 4","item 5"
	};

	public List<string> Items
	{
		get { return t; }
	}

	public CBItems()
	{
	}
}

here's my screencast video for demo http://screencast.com/t/w6UZNCfptc take note that I am not clicking on the items.. I just hover it and pressed Enter key.

How do I get rid of that behvior?

Thanks!



WPF SelectedItem from one ListView and show Relational Data in the Other

$
0
0

Hi Guys,

I'm creating a WPF application, allowing a user to enter in details using CRUD operation using Entity Framework (also using a Repository pattern).

So far, I've created an Application that allows a user to enter a 'Prospect' client. I am able to edit this 'Prospect, add a new one and able to delete with ease. 

This 'Prospect' though has a Foreign Key relation within another table known as 'ProspectMeeting', taking the ProspectID from the 'Prospect' table. 

When I 'Select' a 'Prospect' from the ListView though, it doesn't show the data of that selected 'Prospect'. Further more, when I select a 'Prospect' from the ListView, the command should be enabled for me to add a 'ProspectMeeting' but when I do add, it crashes and produces this error;

Unable to cast object of type '*ProspectListViewModel' to type '*.ProspectViewModel'.

This is the code that it throws the error at (this is in the ProspectMeetingView);

private void btnAddMeeting_Click(object sender, RoutedEventArgs e) { ProspectMeetingView view = new ProspectMeetingView(); ProspectMeetingViewModel meeting = new ProspectMeetingViewModel();

//Throws the error on this line here// meeting.Prospect = (ProspectViewModel)this.DataContext; meeting.Mode = Mode.Add; view.DataContext = meeting; view.ShowDialog(); }

The Image below is the image of what I want to achieve - So hope that gives a better understanding of what I want to achieve. 

In my repository I use this to get a List of 'ProspectMeetings' using the ProspectID;

public List<ProspectMeeting> GetMeetingByProspect(int _ProspectID)
        {
            using (var context = new DBEntities())
            {
                return context.Prospects.First(i => i.ProspectID == _ProspectID).ProspectMeetings.ToList();
            }
        }

In my ProspectViewModel, I use this Observable Collection to get the data from the 'ProspectMeetingViewModel;

private ObservableCollection<ProspectMeetingViewModel> prospectMeetings = null;
        public ObservableCollection<ProspectMeetingViewModel> ProspectMeetings
        {
            get { return GetProspectMeetings(); }
            set
            {
                prospectMeetings = value;
                OnPropertyChanged("ProspectMeetings");
            }
        }

        internal ObservableCollection<ProspectMeetingViewModel> GetProspectMeetings()
        {
            ProspectMeetingRepository c = new ProspectMeetingRepository();
            prospectMeetings = new ObservableCollection<ProspectMeetingViewModel>();
            prospectMeetings.Clear();

            foreach (DataObjects.ProspectMeeting i in c.GetMeetingByProspect(this.ProspectID))
            {
                ProspectMeetingViewModel prospectMeeting = new ProspectMeetingViewModel(i);
                prospectMeeting.Prospect = this;
                prospectMeetings.Add(prospectMeeting);
            }
            return prospectMeetings;
        }

And in my ProspectListViewModel;

private ProspectListViewModel() : base("")
        {
            this.ProspectList = GetProspects();
        }

        private ProspectViewModel selectedProspect = null;
        public ProspectViewModel SelectedProspect
        {
            get
            {
                return selectedProspect;
            }
            set
            {
                selectedProspect = value;
                OnPropertyChanged("SelectedProspect");
            }
        }

        private ObservableCollection<ProspectViewModel> prospectList = null;
        public ObservableCollection<ProspectViewModel> ProspectList
        {
            get
            {
                return GetProspects();
            }
            set
            {
                prospectList = value;
                OnPropertyChanged("ProspectList");
            }
        }

        internal ObservableCollection<ProspectViewModel> GetProspects()
        {
            if (prospectList == null)
                prospectList = new ObservableCollection<ProspectViewModel>();
            prospectList.Clear();

            foreach (DataObjects.Prospect i in new ProspectRepository().GetAll())
            {
                ProspectViewModel c = new ProspectViewModel(i);
                prospectList.Add(c);
            }
            return prospectList;
        }


I've been following this link to help me but I've become unstuck. Personally, When i look through my code, I think that it has something to do with the Repository not getting the data. But I am not too sure.

I hope some one could advice or me or help me with this issue. If more code needs to be added then just let me know, I only added the data that I thought was appropriate. 

Many thanks,

Greg.

Customize a gridView column based on its value ????

$
0
0
Dear all,

I have a gridView control which inside a list view object.
The grid view control is displaying data issue from an SQL request.
The return data are bind to this grid view.
What I have trying to do is that the first column of the return data contains a Status information which can take value 0,1,2...
Basedon this value I would like to diapplay in that column an image instead of values..like as follow somehow:

if gridView.column(0)= 0 then gridView.Column(0).value="Ok.jpg
if gridView.column(0)= 1 then gridView.Column(0).value="bad.jpg
if gridView.column(0)= 2 then gridView.Column(0).value="unknown.jpg


How to perform this in WPF?

Thanks for help
regards
serge
Your experience is build from the one of others

WPF OnMouseMove BUG ???

$
0
0

Hi guys! I've found something interesting about MouseMove event in WPF. It's seems to me like a bug but I'm not 100% sure.

Here is what is all about.

Imagine this situation. We have same item (ellipse, rectangle, button...) which we want to move over the Canvas. The logic which make item move is in Canvas_MouseMove() handler. We move item changing it's  Canvas.Top and Canvas.Left property using Canvas.SetTop and Canvas.SetLeft. We have one timer which task is to move our item on desired location after for example 1 second. We re-set this timer to countdown every time when we execute Canvas_MouseMove() handler.

When problem occur?

When we move mouse over canvas, we invoke Canvas_MouseMove handler and move our item, for exmaple increase it's Cnavas.Top poperty by 10. We position mouse cursor on our "desired" position, the same position where our timer will move item. Then we stop to move mouse and wait for timer tick (run out). When timer run out, timer's handler will move item on desired position beneath the mouse cursor. At this moment we got anEXTRA mouse move event and as a result we move our item by incrementing item's Canvas.Top property by 10.

Here is code example of problem.

In this code example we have one button on Canvas which is moved by Canvas_MouseMove handler. In Canvas_MouseMove() we just increment button's Canvas.Top property by 10. We also have one red rectangle which represent area where button will bi after timer tick so that is place where we left mouse cursor after moving. The "count" variable is here just to show us how many times we have entered in Canvas_MouseMove().

To demonstrate problem do folowing steps.

1. Run application

2. Move mouse around, just to see how button will go down

3. Move mouse inside red rectangle and left mouse there.

4. Wait 1 second and monitor Output window in Visual Studio

You will see how button move to desired location and immidiately after, move by 10 down.

<Window x:Class="WpfApplication5.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:MyNamespace="clr-namespace:WpfApplication5"
  Title="Window1" Height="300" Width="300" ><Canvas MouseMove="Canvas_MouseMove" Background="AliceBlue"><Rectangle Canvas.Top="10" Canvas.Left="50" Stroke="Red" Height="20" Width="40"></Rectangle><Button Name="btnButton" Canvas.Top="50" Canvas.Left="50">Button</Button></Canvas></Window>
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.Diagnostics;
using System.Windows.Threading;

namespace WpfApplication5
{
	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class Window1 : Window
	{
		private DispatcherTimer snapTimer;
		private int count = 0;

		public Window1()
		{
			InitializeComponent();
			this.snapTimer = new DispatcherTimer();
			this.snapTimer.Tick += new EventHandler(SnapTimer_Tick);
			this.snapTimer.Interval = TimeSpan.FromMilliseconds(1000);
		}

		void SnapTimer_Tick(object sender, EventArgs e)
		{
			snapTimer.Stop();
			Canvas.SetTop(btnButton, 10);
			
		}

		private void Canvas_MouseMove(object sender, MouseEventArgs e)
		{
			snapTimer.Stop();
			snapTimer.Start();

			double top = Canvas.GetTop(btnButton);
			Canvas.SetTop(btnButton, top + 10);
			Trace.WriteLine("Move " + count++);
		}
	}
}

What is happened here? Any explanation.

Thanks in advance,

Nikola

 

Friendly DataGrid Header Text with AutoGenerateColumns True

$
0
0

Here's the deal:

I'm setting a DataTable object to DataGrid ItemsSource property. I don't know the DataTable's structure, it is dynamically retrieved.

So, in the DataGrid I set AutoGenerateColumns to True.

However, the Headers text are all ugly. Is there some property in the DataTable to set the friendly column name? If there is, the DataGrid will recognize it?


Take a look at WPF FlashMessage
About.me

Best Approach for Multiple WPF Projects

$
0
0

I would like to develop a WPF system with multiple modules.

A single main menu screen (main window) will be used to show all buttons to each module.

When click on any button on the main menu, the current window will be changed to that module. (Not Popup another window)

The main concern is how to let each module complied, updated and deployed (as a setup) seperately.

My idea is as follow

MySystem (solution)

- Module1 (project)

- Module2 (project)

but how to build the main menu that can open Module1 and Module2 in its own window?

If create another project let say MainMenu, and add Module1 and Module2 as reference.

If any module updated, MainMenu must add new reference again and recompiled and deployed again. How to prevent this? any suggestion? 


DATA BINDING WITH IMAGE WITH LAYERS

$
0
0
HI I am new to wpf such that I am currently working on a project where have to design floor plan with selection similar to seat selection, now I have designed layers on the floor plan for different flats using expression studio and have used this in silverlight application till here no problem now i want to know how to bind this layers with database such that when specific flat is selected and saved it should not be available for booking and on application restart the app should fetch from database the booked flat and should high-lite that specific flat as booked similar to online seat selection and sorry for this naive question. 

ali.khan

Make a UserControl not focusable

$
0
0

Hello,

Is it possible to have a UserControl which does not take the focus ? I have an software composed with many "userControl" and one of them has to behave like a keyboard. It has only buttons, so when I click on one of the buttons, I don't want to lose the focus of the last element.

I tried with the property "Focusable" but it doesn't work.

I also tried to call the fonction SetStyle(...Selectable, false) in my constructor but I have an error "SetStyle does not exist in the current context..."

Thank you in advance !

PS : Sorry if my message contains mistakes, english is not my native language ;-)

ScrollViewer to scroll freely

$
0
0

I have a stackpanel (stackPanel1) which is inside a scrollviewer.

I have 2 textboxes at the top of stackPane1 then another stackpanel (stackPanel2) which have two buttons, then another stackpanel(stackPanel3) that contains 2 textboxes.

Layout is like so:

scrollViewer
    stackPanel1
            textbox1
            textbox2
            stackPanel2
                    button1
                    button2
            stackPanel3
                    textbox3
                    textbox4

When I scroll through the contents, the scrollviewer "jumps" over stackpanel2 (i.e. when I click the scrollbar, and drag down, it reaches the top of stackpanel2 then "jumps" over button1 and button2 proceedes to the top of stackPanel3 and stops)

But I want the scrollviewer to not "jump" over the contents of stackpanel2. How will I accomplish this without changing the layout?

Thanks.




How to load and save MERGEFIELD ( \field ) entries in RichTextBox

$
0
0

Hello,

I load RTF-Content at runtime from database into a RichTextBox. This content can contain MERGEDFIELDs with the RTF \field tag. The RTF is loaded and saved with TextRange and DataFormats.Rtf  as shown in many other entries.

My Problem now is, that the \list entry is lost when I save the RichTextBox back to store.

Here is a sample:

loaded rtf:

{\rtf1\deff0{\fonttbl{\f0 Times New Roman;}{\f1 Arial;}}{\colortbl\red0\green0\blue0 ;\red0\green0\blue255 ;}{\*\listoverridetable}{\stylesheet {\ql Normal;}{\*\cs1 Default Paragraph Font;}{\*\cs2\sbasedon1 Line Number;}{\*\cs3\ul\cf1 Hyperlink;}{\*\ts4\tsrowd\ql\trautofit1\tscellpaddfl3\tscellpaddl108\tscellpaddfr3\tscellpaddr108\tsvertalt\cltxlrtb Normal Table;}{\*\ts5\tsrowd\sbasedon4\ql\trbrdrt\brdrs\brdrw10\trbrdrl\brdrs\brdrw10\trbrdrb\brdrs\brdrw10\trbrdrr\brdrs\brdrw10\trautofit1\tscellpaddfl3\tscellpaddl108\tscellpaddfr3\tscellpaddr108\tsvertalt\cltxlrtb Table Simple 1;}}\nouicompat\splytwnine\htmautsp\sectd\pard\plain\ql{\b\f1\fs20\cf0 Merkmale:}\b\f1\fs20\cf0\par\pard\plain\ql\par\pard\plain\ql{\field{\*\fldinst{\cf0 MERGEFIELD #1301}}{\fldrslt{\cf0 <<#1301>>}}}\par}

saved rtf:

{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Arial;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs20\f2\cf0 \cf0\ql{\f2\b {\ltrch }\li0\ri0\sa0\sb0\fi300\ql\par}{\f2\b {\ltrch Merkmale:}\li0\ri0\sa0\sb0\fi0\ql\par}{\fs24\f0 \li0\ri0\sa0\sb0\fi0\ql\par}{\fs24\f0 {\ltrch <<#1301>>}\li0\ri0\sa0\sb0\fi0\ql\par}}}

Is there any way to get that correctly handled by the RichTextBox? I want to be able to make changes in the richtextbox without losing the MERGEDFIELD entry.

Thank you very much,

Tobias

Capture key strokes in ElementHost hosted WPF control

$
0
0

Hi.

In our application we handle some key strokes in a centralized manor, for instance switching between views using special keys.

This works fine for the Windows Forms part of our application. But we are also using some WPF user controls through the ElementHost-control. When for instance tab is clicked in these, they receive keyboard focus and subsequent key strokes are not received in our main form.

Is there any way to trap these key strokes in Windows Forms?

Regards,

Bjørn Terje Svennes

Viewing all 18858 articles
Browse latest View live