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

How to add a custom WPF component in another wpf application

$
0
0

Hi,

I have created a custom WPF component library.

Now I want to use that component in another wpf application. Suppose the component is  a textbox.

I have used MVVM for the WPF component. 

When I'm adding that component to another client/application how can I set the dataContext of that component?


How to get smooth video in WPF?

$
0
0

Hi all,

Im my WPF application (C# / .Net 4.0), I need to be able to play a video (.AVI) fullscreen on a second display.  I achieved this very quickly using the MediaElement control using a borderless window.

I've now realised that the playback is very choppy in comparison to playing the same video in Windows Media Player.  It's just passable on Windows 7 (where it seems to drop frames), but it's quite bad on XP as you see lots of "tearing".

Seen there is a few mentions on the web that WPF just can't display smooth video, but I'm finding it hard to believe this can be the case.  Can anyone offer any help on how I can get smooth video from within my WPF application.  My current (horrendous) solution is to shell out to MPlayer.exe!!  :o(

Many thanks in advance for any help you can give,

Paul.

Code behind Disabled item in Context menu

$
0
0

Hello 

Please, i need your help to solve the following error:

I have several ContextMenu in my treeview, and I would  to manage the items  in the code behind. 
I 've used this code to check or uncheck a MenuItem . 

 ContextMenu contextMenu = tvi.Resources["FolderContext"] as ContextMenu;
            MenuItem mi = contextMenu.Items[0] as MenuItem;

           mi.IsChecked = true;

But when I try to disable the MenuItem by adding this code. 

mi.IsEnabled = false;

Nothing happen, the menuitem still enable.

Thanks in advance for  your help

Header template is setted but the header is null

$
0
0
I set a header template using dynamic XAML:
DataGridTemplateColumn tc = new DataGridTemplateColumn();publicstaticstring GetHeaderDataTemplate(string bindingPath)
{return@" <DataTemplatexmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" ><TextBlock Text=""{Binding Path="+ bindingPath + @"}""TextWrapping=""Wrap"" Foreground=""#FF1EA800"" FontWeight=""Bold"" /> </DataTemplate>";
} 

tc.HeaderTemplate = (DataTemplate)XamlReader.Parse(GetHeaderDataTemplate(someText));



But there is nothing in the place of datagrid column header. It is just an empty place. So I tried to get access to the header and got null reference exception.
How to set a header data template in the right way?





XamlParseException occurred

$
0
0

'No matching constructor found on type 'System.Windows.Media.Imaging.RenderTargetBitmap'. You can use the Arguments or FactoryMethod directives to construct this type.'

MemoryStream ms = new MemoryStream();
            FlowDocument fd = new FlowDocument();         
            XamlWriter.Save(myFD, ms);
            ms.Seek(0, SeekOrigin.Begin);
            fd = XamlReader.Load(ms) as FlowDocument;  //exception occurs here.

myFD is a FlowDocument. As you must have guest it has got an image inserted into it. It is the the image that is causing this error to occur. As soon as I remove the image, it'll work. 


To open the child control with url when instance of application is already opened

$
0
0

Hello All,

We developed WPF application where initial screen with grid view, when we click on grid view column ,a new tab will be opened which has the feature to copy the url of the new tab and will be displayed when clicked on the url with a new instance of the application,

the issue   we are facing is we need to close the exisiting instance to browse the url else its throwing error,and we want to have a feature,when the url is browsed it needs to open a new tab in the existing instance.

Is it feasible if yes please provide us information how to approach?

Thanks and Regards,

Ruth

Problem when selecting items to drag

$
0
0
I have noted that, when I press the mouse button over a ListViewItem or TreeViewItem, the item becomes selected/deselected before the mousebutton_up event. So, if I have multiple items selected and click over an item with the CTRL key pressed to drag the selection, the item clicked becomes unselected and I need to click a second time to reselect the item. Is there a solution for this weird behaviour of the itemscontrols in WPF?

Codelines

Building a simple keypad

$
0
0

Dear all,

IN a WPF application I need to build a simple keypad with number 0 to 9. Then when clicking on corresponding button I need to send the corresponding associated value to the focus text box.

What is the best way to do that ?

I have a see a lot of sample wpf keyboard but are too complicated to insert in my scenario and need to build a more simple one.

Thanks for help

regards 


Creating a standalone WPD app with multiple pages

$
0
0

Hi.

I am creating a WPF app for my college mini project. The app consist of a main windows with a background image and based on what button the user selects on the main window it has to display other pages while retaining the background image. I don't want it to have multiple windows or use the Navigationwindow as it is not exactly navigating between pages and I also want to be able to pass data between pages or by whatever means I would be able to accomplish this. This application is a demo app for using embedded SQL in my college project. I really have no idea how to go about this. Please help me. Thanks in advance. Any help would be appreciated.

Thanks.

IDataErrorInfo, Validation.ErrorTemplate does not show on initial window start

$
0
0
I have a situation where the ErrorTemplate does not show on the initial window start.  I do see that the data validation is called when the window is loaded but it seems like the information is discarded or lost.  As soon as I type something everything works of course.  I could force an UpdateSource but that seems like a terrible hack - especially if I have 15 controls on my page. 

Here is simplified version of the code that shows the problem.
<Window x:Class="Test.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" SizeToContent="WidthAndHeight" DataContext="{Binding RelativeSource={RelativeSource Self}}" WindowStartupLocation="CenterScreen"><Grid Margin="5" ><StackPanel><Label Content="Password:"/><TextBox Height="23" Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Password, ValidatesOnDataErrors=true}" Width="150" /></StackPanel></Grid></Window>

Here is the code behind:

using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows;

namespace Test
{
    public partial class Window1 : Window, IDataErrorInfo, INotifyPropertyChanged
    {
        public Window1()
        {
            InitializeComponent();
        }

        public string Password
        {
            get
            {
                return password;
            }
            set
            {
                if (value != password)
                {
                    password = value;
                    NotifyPropertyChanged(MethodBase.GetCurrentMethod().Name);
                }
            }
        }
        private string password;

        // IDataErrorInfo Interface implementation
        public string Error
        {
            get { throw new NotImplementedException(); }
        }

        public string this[string propertyName]
        {
            get
            {
                if (propertyName == "Password")
                {
                    if (string.IsNullOrEmpty(password) || password.Length < 5)
                        return "Password must be longer than 4 characters";
                }
                return null;    // no error - actually would be better to throw an exception on an attempt to validate an unexpected property but this is just an example...
            }
        }

        // INotifyPropertyChanged event
        public event PropertyChangedEventHandler PropertyChanged;

        // a nice helper function for property notifications
        protected void NotifyPropertyChanged(string propertySetterMethodName)
        {
            // Remove the set_ from the property setter's method name to obtain the propertyName:
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertySetterMethodName.Remove(0, 4)));
        }
    }
}

ListBox ItemTemplate DataTemplate TextBox needs to be automatically keyboard focused when Item is selected

$
0
0

Hello,

I have a ListBox with DataTemplated items, I need to get a TextBox (in the DataTempate) keyboard focused when the item is selected.

I couldn't get it to work using trigger in a style because DataTemplate controls are out of the focus of the style.

Does someone have a solution to this issue?

Thanks in advance.

Zictom

How to write style code from XAML in code behind?

$
0
0

How can I write this code in code behind?

<Grid.Resources><Style x:Key="ToolTipDataPointStyle" TargetType="chart:LineDataPoint"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="chart:LineDataPoint"><Grid x:Name="Root" Opacity="1"><ToolTipService.ToolTip><StackPanel Margin="2,2,2,2"><ContentControl Content="{Binding Path=Key}" ContentStringFormat="TimeStamp: {0}"/><ContentControl Content="{Binding Path=Value}" ContentStringFormat="Value: {0}"/></StackPanel></ToolTipService.ToolTip><Ellipse StrokeThickness="{TemplateBinding BorderThickness}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}"/></Grid></ControlTemplate></Setter.Value></Setter></Style></Grid.Resources>

Visual Studio 2012 Express C#: WPF/MVVM Quick Tutorial - CodeProject: How to open this project?

$
0
0

Hi all,

I downloaded the examples of WPF/MVVM Quick Start Tutorial by Barry Lapthorn (10 Oct 2012) from http://www.codeproject.com/Articles/165368/WPF-MVVM-Quick-Start-Tutorial. I used my Visual Studio 2012 Express to open this project by clicking MvvmExample.suo of this project. I got the following:

Solution'MvvmExample'(0 projects)

Example1 (unavailable)

Example2 (unavailable)

.................................

.................................

Example6 (unavailable)

MicroMvvm (unavailable)

see the attached image:

Please kindly help and advise me how to open this project correctly in my Visual Studio 2012 Express.

Thanks in advance, Scott Chang

Crystal Report in WPF using VB.net

$
0
0

Hello Everyone,

I've a project where I need to integrated existing Crystal report using WPF VB.Net. Can anybody please post the sample project or help me? I'm stuck with this issue for too long. Any help will be greatly appreciated.

Thanks

How to handle a CollectionView refresh

$
0
0

In reference to this thread,

I have some combo and ListView binded to two CollectionViews.
All work well until I refresh the underlying ObservableCollection: all combos display no items.

<ComboBox Name = "cboButton1"
          ItemsSource="{Binding EncoderMasksView}"
          DisplayMemberPath="MaskDescription"
          SelectedItem="{Binding Handlers.Button1, Mode=TwoWay,
                         UpdateSourceTrigger=PropertyChanged} />

I added a notification system to the class

class Handlers : ObservableObject   // <- Mvvm which implements INotifyPropertyChanged
{  
  private Mask[]  _BindingButtons = new Mask[5]; // One for each button

  public CollectionView EncoderMasksView { get; set; }
  
  private void UpdateCollection()
  {
    try
    {
      _encMasks.Clear();

      _encMasks.Add(new Mask());  // The empty object

      ...
      _encMasks.Add(Mask1);
      _encMasks.Add(Mask2);
      ....
      
      
      if (EncoderMasksView == null)
      {
        // Create the CollectionView to be used in the views
        EncoderMasksView = (CollectionView)new CollectionViewSource { Source = _encMasks }.View;
        EncoderMasksViewFiltered = (CollectionView)new CollectionViewSource { Source = _encMasks }.View;
        EncoderMasksViewFiltered.Filter = Filter_MasksView;
      }
      else
      {
        this.RaisePropertyChanged("Button1");
      }

    }
    catch (Exception ex)
    {
    }
  }

    
  public Mask Button1
  {
    get { return _BindingButtons[(int)EBindingButtons.BUTTON_1]; }
    set { if (value != null) _BindingButtons[(int)EBindingButtons.BUTTON_1] = value; }
  }
    
}
    

After the call to RaisePropertyChanged the Button1_get() is called but the combo remain with no data selected. Why?

Thanks in advance for the suggestions.


Datagrid Copy to clipboard

$
0
0

I have a DataGrid in WPF. The default behavior of the Datagrid will copy cells into the clipboard, but the column Headers are missing. I am trying to intercept the data an insert some headers, but I can't change the ClipBoard.
What am I missing?

private void Grid_CopyingRowClipboardContent(object sender, DataGridRowClipboardEventArgs e)
{                                       
      Clipboard.Clear();
      DataObject data = new DataObject();
      data.SetData(DataFormats.Text, "My Stuff with headers");
       Clipboard.SetDataObject(data);
}


Certified Geek


Compiling problem with crystal report in vs 2010

$
0
0

Hi all,

I am beginner of .net framework... 

I am trying to create crystal report in vs 2010 but getting lots of errors.... while searching on internet get the solution as the l below

"Right click your project, select properties, under the first "Application" tab, CHANGE your "Target framework" to .net Framework 4, because the message above is saying it is currently ".net 4 Client Profile"  

I tried to make changes as suggested but I don't get option 'Target framework' in "Application" tab of project's properties window.

errors are as showing below

The currently targeted framework ".NETFramework,Version=v4.0,Profile=Client" does not include "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which the referenced assembly "CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" depends on. This caused the referenced assembly to not resolve. To fix this, either (1) change the targeted framework for this project, or (2) remove the referenced assembly from the project


BackgroundWorker - FixedDocumentSequence- async = XamlParseException occurred (root element is missing)

$
0
0

I am trying to merge different Flowdocuments asynchronously using BackgroundWorker. The following method is where I receive the  XamlParseException saying root element is missing.

   private List<PageContent> convertFDtoFixedD(FlowDocument fdTemp,string documentFooter,int startingPageNo)
        {
            FlowDocument fd = new FlowDocument();
            using (MemoryStream ms = new MemoryStream())
            {

                System.Windows.Markup.XamlWriter.Save(fdTemp, ms);
                ms.Seek(0, SeekOrigin.Begin);
                fd = System.Windows.Markup.XamlReader.Load(ms) as FlowDocument;
            }

            DocumentPaginator paginator = ((IDocumentPaginatorSource)fd).DocumentPaginator;
            paginator = new DocumentPaginatorWrapper(paginator, new Size(794, 1122), new Size(20, 72), documentTitle, documentFooter,startingPageNo);
            var package = Package.Open(new MemoryStream(), FileMode.Create, FileAccess.ReadWrite);
            Uri packUri;

            packUri = new Uri("pack://" + i.ToString() + ".xps");
            PackageStore.RemovePackage(packUri);
            PackageStore.AddPackage(packUri, package);           
            XpsDocument xps = new XpsDocument(package, CompressionOption.NotCompressed, packUri.ToString());
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xps);
            PrintTicket printTicket = new PrintTicket();
            printTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4);
           // writer.Write(paginator, printTicket);
            writer.WriteAsync(paginator, printTicket); 
            FixedDocumentSequence fds = xps.GetFixedDocumentSequence();

            xps.Close();
            i++;
            return GetAllPages(fds);
        } 

It works absolutely fine without implementing BackgroundWorker when using writer.Write(paginator,printTicket). And it come up with root element is missing error whenever I use writer.WriteAsync with or without implementing BackgroundWorker!                       

When 

Binding Failure on ToolTip Items when Container is Dragged

$
0
0

I have implemented a ToolBar and styling according to the following style. For the images I am using vector graphics from an .xaml resource file

<ResourceDictionaryxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:Caliburn="http://www.caliburnproject.org"><Rectanglex:Key="ToolBarButtonIcon"x:Shared="False"Visibility="{Binding IconVisibility}"HorizontalAlignment="Stretch"VerticalAlignment="Stretch"Width="16"Height="16"><Rectangle.Fill><VisualBrushStretch="Uniform"Visual="{Binding IconSource}"/></Rectangle.Fill></Rectangle><Stylex:Key="ToolBarButton"TargetType="{x:Type Button}"BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"><Setter Property="Content" Value="{StaticResource ToolBarButtonIcon}"/><Setter Property="ToolTip" Value="{Binding ToolTipText}"/><Setter Property="ToolTipService.IsEnabled" Value="{Binding ToolTipServiceEnabled}"/><Setter Property="Caliburn:Action.Target" Value="{Binding}"/><Setter Property="Caliburn:Message.Attach" Value="{Binding ActionText}"/></Style></ResourceDictionary>

This renders the ToolBar great and all looks well, but when I dragged the ToolBar container the images became corrupted

To solve this I include the image binding in a control template so in the end the styles became

<Stylex:Key="ToolBarButton"TargetType="{x:Type Button}"BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"><Setter Property="ContentTemplate"><Setter.Value><DataTemplate><Rectangle x:Shared="False"
                              Visibility="{Binding IconVisibility}"
                              HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                              Width="16" Height="16"><Rectangle.Fill><VisualBrush Stretch="Uniform" Visual="{Binding IconSource}"/></Rectangle.Fill></Rectangle></DataTemplate></Setter.Value></Setter><Setter Property="ToolTip" Value="{Binding ToolTipText}"/><Setter Property="ToolTipService.IsEnabled" Value="{Binding ToolTipServiceEnabled}"/><Setter Property="Caliburn:Action.Target" Value="{Binding}"/><Setter Property="Caliburn:Message.Attach" Value="{Binding ActionText}"/></Style>

Now, the dragging works great

But now there is another problem. The tool tips for the button also become corrupt on the drag operations as do the Caliburn properties. Now, to get around this I have added the ToolTip and ToolTipService.IsEnabled properties to the rectangle, this indeed stops the binding from failing, but it also means that the ToolTip does not show for mouse hover on the very edge of the buttons, the tool tips only show when the mouse is over the rectangle. 

Now I have two questions: 

1. How can I add tool tips to button itself so that the entire button surface will show the tool tip if the mouse hovers over it?

2. How can I handle the breaking of the bindings on the Caliburn properties?

Thanks for your time.


"Everything should be made as simple as possible, but not simpler" - Einstein

RadChart - ToolTip for X axis itself - Telerik

$
0
0

I'm working on a WPF application and using the RadChart control. I'm familiar with the ItemToolTipFormat and DataPointMember="Tooltip" features, but I wonder if the following is possible:

I've attached an image for demonstration:


Is it possible that when I hover with the mouse cursor on the x axis categories, I'll get a tooltip: For example: In the attached image, when I hover on the word May (or Sep or Nov and etc) with the mouse cursor, I will then get a tooltip.

What happens with the mentioned features above, I get a tooltip on the diagram itself, but as mentioned, I want a tooltip on the category itself on the x axis (when I hover on the months' words as displayed in the image).

Thank you in advance for your help!


Viewing all 18858 articles
Browse latest View live


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