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

Convert XAML to OOXML - PresentationML and vice versa

$
0
0

Hi

I am working on a project which requires RichEdit controls text to be converted into PresentationML and vice versa.

RichEdit controls text is Flowdocument, from which I am able to get XAML of the document, now I can convert this XAML into the RTF doucment also, but my requirement is to parse the XAML into PresentationML and viceversa, so that text given in RichText along with formatting can be exported to PPT and changes in PPT can be displayed in the RichText.

Early reply will be appreciated.

Thanks,

Ram


Ram Swami


Material Design In XAML Toolkit

$
0
0

Hi guys,

Just wanted to share the link to the new homepage for Material Design In XAML Toolkit.  

http://materialdesigninxaml.net

If you haven't seen before it's an open source library for WPF bringing Material Design palettes & themes to standard .Net framework controls, with a some extra custom controls thrown in.  Project is moving along quite nicely and is close to a full version 1.0. 

Hope you like!

James


listbox population in xaml

$
0
0

Hi,
I am unable to populate a listbox.
No error is given but nothing is populated. Note that the DataCollection is indeed populated with data

Do you see why?

I am using the following:

<

Windowx:Class="Rustam.frmStudentDetails"

xmlns:scr="clr-namespace:Rustam"


      

Title="Student Details"

      

Height="713"Width="1157"


      

WindowStartupLocation="CenterScreen"


      

Loaded="Window_Loaded"ResizeMode="CanMinimize"Icon="/Rustam;component/Images/Logo.ico">

<Window x:Class="Rustam.frmStudentDetails"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:scr="clr-namespace:Rustam"
        Title="Student Details"
        Height="713" Width="1157"
        WindowStartupLocation="CenterScreen"
        Loaded="Window_Loaded" ResizeMode="CanMinimize" ><Window.Resources><scr:clsStudentViewModel x:Key="StudentViewModel"/></Window.Resources><Grid Name="grdSearch"
              DataContext="{Binding Source={StaticResource StudentViewModel}}"><ListBox
        Name="lstStudents" Width="226"
         DisplayMemberPath="FullName"
         ItemsSource="{Binding Source={StaticResource StudentViewModel}, Path=DataCollection}"
                         HorizontalContentAlignment="Stretch"
                         SelectionChanged="lstStudents_SelectionChanged"
                         /></Grid></window>

clsStudentViewModel code is as follows:
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using System.Collections.ObjectModel;
using DataAccess;

namespace Rustam
{
    public class clsStudentViewModel : INotifyPropertyChanged
    {
        clsStudentAccess _DataManager = new clsStudentAccess();

        #region Constructor - Initialize Product Data Collection
        public clsStudentViewModel()
        {
            DataCollection = _DataManager.GetStudentNamesCol();
        }
        #endregion

        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion

        #region DataCollection Property
        private ObservableCollection<clsStudentDetails> mDataCollection;

        public ObservableCollection<clsStudentDetails> DataCollection
        {
            get { return mDataCollection; }
            set
            {
                mDataCollection = value;
                RaisePropertyChanged("DataCollection");
            }
        }
        #endregion

        #region DetailData Property
        private clsStudentDetails mDetailData;

        public clsStudentDetails DetailData
        {
            get { return mDetailData; }
            set
            {
                mDetailData = value;
                RaisePropertyChanged("DetailData");
            }
        }
        #endregion
    }
}


How comes Storyboard is so efficient?

$
0
0

I checked a few ways, but but none of them works properly:

1. System.Timers.Timer - takes longer time, not precise.

2. System.Windows.Forms.Timer - takes longer time, not precise, UI gets frozen.

3. Parallel endless thread loop - precise, but high CPU usage.

The only working way:

1. Storyboard - precise, low CPU usage.

Questions:

1. How comes Storyboard is so efficient?

2. Can i make my own Storyboard inside WPF? If yes, how?

3. Is it true that Storyboard executes UI in a parallel thread?

How to stop animation in WPF?

$
0
0

Question: How to stop animation in WPF at any given moment?

Note: Animation is done using the DoubleAnimation and Storyboard classes.

Code:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            this.Loaded += MainWindow_Loaded;
        }

        Line line;

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Canvas canvas = new Canvas();
            canvas.Background = Brushes.Black;
            this.Content = canvas;

            line = new Line();
            line.Stroke = Brushes.White;
            line.X1 = 0;
            line.Y1 = 0;
            line.X2 = 100;
            line.Y2 = 100;

            canvas.Children.Add(line);

            Animation();
        }

        private void Animation()
        {
            DoubleAnimation DB = new DoubleAnimation();
            DB.By = 100;
            DB.AutoReverse = true;
            DB.RepeatBehavior = RepeatBehavior.Forever;
            DB.Duration = new Duration(TimeSpan.FromMilliseconds(100));

            string name = "line";
            RegisterName(name, line);

            Storyboard SB = new Storyboard();
            Storyboard.SetTargetName(DB, name);
            Storyboard.SetTargetProperty(DB, new PropertyPath(Line.X2Property));
            SB.Children.Add(DB);

            SB.Begin(this, true);

            this.MouseDown += delegate
            {
                SB.Stop(); // Does not stop.
            };
        }
    }

How to use Print server and Print queue in C#

$
0
0

I have a WPF application , from there it prints to a shared  printer  , Now the problem is that we need to install the printer driver in each machine ., So Client suggest to use a print server and from WPF it needs to send document to Print server ,specifying the Printer name 

How do we achieve this in C# - WPF application ?  


Regards Sooraj

WPF ContextMenu Binding multilevel items.

$
0
0

Hi All,

I faced an binding issue regarding ContextMenu. My ContextMenu looks like:

MenuItem1

MenuItem2

MenuItem3

OthersMenuItem

OtherMenuItem1

OtherMenuItem2

OtherMenuItem3

How to create binding source object, and how to binding the source to ContextMenu?

Thanks for your help.

What Is the XAML Version of case key.?

$
0
0

I'm just looking to use a simply, easily re-assignable way of assigning my keys to perform certain functions,

When I'm on a main playing screen for a game, I'd like the keys to perform basic player functions, and in a menu screen they would simply navigate the menu, etc.


RichTextControl -Font size is not written correctly to rtf file

$
0
0

Hi,

I have a richtextbox control. I am saving its content in an RTF document using the below code: -

            TextRange textRange = new TextRange(RichTextCtrl.Document.ContentStart,
                                                RichTextCtrl.Document.ContentEnd);
            FileStream file = new FileStream("BBB.rtf", FileMode.Create);
            textRange.Save(file, System.Windows.DataFormats.Rtf);
            file.Close();

If I change the font size to 22 using below code :-

           RichTextCtrl.Selection.ApplyPropertyValue(Inline.FontSizeProperty, "22");
            RichTextCtrl.FontSize = 22;

The font size in RTF file is written as "fs33" that means font size of 16.5 as per the RTF standards.

Could you please help me to solve this issue. If I open the rtf file in word also it shows 16.5.

This is the rtf output which is written.

{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f0\cf0 \cf0\ql{\fs33\f0 {\ltrch I have a richtextbox control.}\li0\ri0\sa100\sb100\fi0\ql\par}
}
}

Regards,

Sharda.

Custom PopupWindowAction (PRISM)

$
0
0

I need to implement my own version of PopupWindowAction to have the content displayed in a Telerik's RadWindow (which is NOT derived from Window) instead of a plain window.

So I wrote a class (called RadDialogAction) that inherits TriggerAction<FrameworkElement> and overrode the Invoke method as follows:

protected override void Invoke(object parameter)
{
	var args = parameter as InteractionRequestedEventArgs;
	if (args == null) return;

	INotification notification = args.Context as INotification;
	if (notification == null) return;

	RadWindow radWindow = new RadWindow();
	radWindow.Owner = Window.GetWindow(this.AssociatedObject);

	radWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
	// WindowContent is a DP that represents the "view"
	radWindow.Content = this.WindowContent;
	var dc = this.WindowContent.DataContext as IInteractionRequestAware;
	if ( dc != null )
	{
		dc.Notification = notification;
		dc.FinishInteraction = args.Callback;
	}
	radWindow.Width = this.WindowContent.Width;

	radWindow.ShowDialog();
}

And in the invoking view:

<prism:InteractionRequestTrigger SourceObject="{Binding ImageSelectionRequest, Mode=OneWay}"><uc:RadDialogAction  ><uc:RadDialogAction.WindowContent ><views:ImageSelector /></uc:RadDialogAction.WindowContent></uc:RadDialogAction></prism:InteractionRequestTrigger>
ImageSelectionRequest is a class that implements INotification.


Here the embedded view (ImageSelector) has an Ok button and a Cancel button hooked to commands in the view model. In both command handlers, the FinishInteraction method is called. And then the dialog should close, but of course it stays open. So my question is: How do I know when the interaction is "finished" so that I can close the window?

It is certainly feasible for if I use the regular PopupWindowAction class instead, the dialog closes when FinishInteraction executes.


Choosing the proper BitmapDecoder type

$
0
0

Hello. Up until now, when a user wishes to open an image I've been scanning the file name extension and based on the result ("bmp", "jpg", etc) I choose the decoder type (BmpBitmapDecoder, JpgBitmapDecoder, etc). Is there a more elegant/robust way of doing this? Thank you in advance.

-L

Want to be the Microsoft TechNet WPF Guru for September?

$
0
0

All you have to do is add an article to TechNet Wiki from your own specialist field. Something that fits into one of the categories listed on the submissions page. Copy in your own blog posts, a forum solution, a white paper, or just something you had to solve for your own day's work today.

Drop us some nifty knowledge, or superb snippets, and become MICROSOFT TECHNOLOGY GURU OF THE MONTH!

This is an official Microsoft TechNet recognition, where people such as yourselves can truly get noticed!

HOW TO WIN

1) Please copy over your Microsoft technical solutions and revelations toTechNet Wiki.

2) Add a link to it on THIS WIKI COMPETITION PAGE (so we know you've contributed)

3) Every month, we will highlight your contributions, and select a "Guru of the Month" in each technology.

If you win, we will sing your praises in blogs and forums, similar to the weekly contributor awards. Once "on our radar" and making your mark, you will probably be interviewed for your greatness, and maybe eventually even invited into other inner TechNet/MSDN circles!

Winning this award in your favoured technology will help us learn the active members in each community.

Feel free to ask any questions below.

More about TechNet Guru Awards

Thanks in advance!
Pete Laker


#PEJL
Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over toTechNet Wiki, for future generations to benefit from! You'll never get archived again, and you could win weekly awards!

Have you got what it takes o become this month's TechNet Technical Guru? Join a long list of well known community big hitters, show your knowledge and prowess in your favoured technologies!

UserControl Button IsCancel not honoring e.Handled still calls DialogCancelCommand

$
0
0

Has anyone come across the .NET Framework *BUG* in the WPF button where it does not honor the "e.Handled = true" value in the OnClick method(s) and instead proceeds to processing Command bindings? 

Specifically I'm slowly uplifting code from the WinForms style of programming over to MVVM.  I have a user control with a Cancel button which has a ClickEventHandler wired up and has the IsCancel = true set.  In the code behind the UserControl is wired into the host container Window's Closing event in order to prevent the user from closing the form via the X which the control is dirty.  This is done by setting the Window's Closing e.Handle = true. 

What I'm seeing is the Window's Closing Event is being called twice as the when the Button is wired up without a Command but is marked with IsCancel = True, the framework code is still calling theMS.Internal.Commands.CommandHelpers.ExecuteCommand(Window.DialogCancelCommand, null, this);  In other words the Button.OnClick() and BaseButton.OnClick() simply ignore the RoutedEventArgs.Handled property and keep chugging on calling the MS.InternalCommands.CommandHelpers.ExecuteCommandSource(this) andExecuteCommand() with no regards

So far the only thing I can come up with is to convert the EventHandlers over to ICommands.  Anyone else have ideas on getting around this issue?

Toggle the value in WPF Textbox

$
0
0

Hello,

I have a textbox which binds to a SocialSecurityNumber. Now I need to display "*"(asteriks) for the number in the textbox on basis of some boolean value in LostFocus of that textbox. Now on GotFocus the original value gets displayed.

So if i entered SSN as 12345 then on LostFocus it displays ***** and again on GotFocus it displays as 12345.

The issue is that the setter of property to which it is bind assigns the value to the object which gets saved ultimately.

So if i turn the number to asteriks then there are chances that asteriks gets saved in the object and hence then in database.

Please suggest if any other approach i can implement for this scenario.

Thanks,

Abdi

KeyBinding without focus

$
0
0

I have a WPF application that uses the MVVM pattern.  The XAML code for my view (ShellBase is my base class that inherits from UserControl):

<shell:ShellBase.InputBindings><KeyBinding Command="{Binding AddBookmarkCommand}"
				Key="F1" /><KeyBinding Command="{Binding AddBookmarkCommand}"
				Modifiers="Control"
				Key="B" /></shell:ShellBase.InputBindings>

My view model has the following code:

public ICommand AddBookmarkCommand {
	get { return GetCommand(() => AddBookmarkCommand, ExecuteAddBookmarkCommand); }
}

private void ExecuteAddBookmarkCommand() {
...
}

GetCommand() is a method in my view model's base class that uses the DevExpress ViewModelBase class' GetProperty() method. 

It is only at certain times that a control in my view has focus.  When that is true, the ExecuteAddBookmarkCommand() method gets called when F1 is pressed.  However, most of the time there is no control with focus.  Then, this command does not get called.  I even tried to add a KeyDown event handler in the view code behind but that doesn't get called unless there's a control that has focus.

So, my question is: Is there a way to get a KeyBinding to work when there is no control with focus?  I just want a way to call a method in my view model when the user presses a key.





WPF Custom controls

$
0
0

Hi,

I've created a WPF custom Checkbox inheriting from a Checkbox control.

custom control 

publicclassCustomCheckBox:CheckBox

{

staticCustomCheckBox()

{

//DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomCheckBox), new FrameworkPropertyMetadata(typeof(CustomCheckBox)));

}

When I reference the above control in a WPF Application, with the DefaultStyleKeyProperty commented,

I couldn't see the style applied to the control in Generic.xaml, when the application is executed.

MainWindow.xaml

<Window>

<Grid>

<control:CustomCheckBox>I'm a custom checkBox</control:CustomCheckBox>

</Grid>

</Window>

When DefaultStyleKeyProperty is uncommented I see the style applied, but the content of the control doesn't appear when executed. 

How will I be able to retain the style of the custom control, while the DefaultStyleKeyProperty is commented?

Any help appreciated.

Thanks.

Harika

how to draw an ellipse in inkcanvas of wpf?

$
0
0

现在要用inkcanvas画图,想画一个可以用inkcanvas自带的橡皮能够擦出的圆,应该怎么画?用ellipsegeometry和ellipse都试了,能画出来,但是不能用橡皮擦擦掉,求解

recently i want to draw a ellipse in wpf using inkcanvas,i used ellipse and ellipsegeometry to draw a ellipse, but it can not be removed by eraser of inkcanvas, so how can i draw an ellipse which can be remove by eraser in inkcanvas

TranslatePoint with TextBlock and Run

$
0
0

Hello! Can I somehow detect the location of Run inside TextBlock? I have several Run's inside TextBlock and I want to handle mouse click and place TextBox (for editing Run's Text) exactly over clicked Run.TranslatePoint function takes UIElement as argument so it will not work with Run (which is deriven from ContentElement). But I see that MouseLeftButtonDown event is firing correctly so WPF internal system "knows" about Run bounds. Can I somehow get this information?

I do not want to place these Runs into separate simple TextBlocks because of performance reasons (There will be about 100 complex or 500 simple TextBlocks in the app's window).

Thank you. 


Vladimir Khil

how to call procedure in wpf application in prism design pattern

$
0
0

Hi guys,

I'm working in wpf application with MVVM and prism pattern.

Right now we are using NHibernate for backend operations, but i want to call a procedure instead of NHibernate

can you guys suggest me the right way to do this.

thanks in advance

Error: Unable to cast 'MS.Internal.Controls.AddInHost' to type 'System.Windows.Controls.UserControl

$
0
0

Hi,

I am facing problem for implementing WPF addin framework in my application. In my application, I have to create instance of Usercontrol into separate appdomain and pass the reference to host application which is running into another appdomain

I have created usercontrol instance separate appdomain and cast it to "System.Windows.FrameworkElement" as per addin framework guideline and I am able to pass reference of framework instance into host application. But when I am trying to convert FrameWorkElement into usercontrol in hostapplication appdomain, I am getting exception  "Unable to cast object of type 'MS.Internal.Controls.AddInHost' to type 'System.Windows.Controls.UserControl'."

Can any one please tell me whether it is possible to convert Framework element into userControl.

Regards

Ravi

 

 

 

Viewing all 18858 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>