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

Showing emoji in wpf web bowser using style-background url()

$
0
0

hello everyone
Is there a way to use style-background url() in wpf web-browser..
currently i have to change it in

<img src="url goes here">

which is not a correct way

I am trying to build a c# app which uses API to get data which is entered by some random person on website using froala online editor which provide emoji support. I am storing data in HTML format in db it gives me image as but emojis as 
I can not search in string for URL's as content may be large and user may enter some valid URL also..

I want to show those emojis in my app.

What I have tried:

i tried using some libraries of but not successful. :(


implementing multi rect tracker

$
0
0

Hi All,

How can I implement CMultirectTracker(MFC) in wpf. Suppose I will have multiple objects in view like rectangle, circle etc. I can be able select one object at a time and resize and also "Select all"  option. i.e user can select all the object and resize.

Thanks

Mrutyunjaya

How to get WPF to be date culture sensitive

$
0
0

Gentlefolk,

I have an application that needs to display dates in a culture sensitive way (in the UK short dates are displayed as DD/MM/YYYY). However, I am having to go through a few hoops to get WPF to honour (= honor) the UK culture.

As an example of my problem, below is some code that presents three labels that should all show the date 12th December 2000 in short format...

XAML:

<Window x:Class="DateCulture.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DateCulture"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525"><Window.Resources><local:DateTimeToString x:Key="DateTimeConverterRes"/></Window.Resources><Grid><Label x:Name="Label1" Content="{Binding Path=FirstDecember2K}" HorizontalAlignment="Left" Margin="177,76,0,0" VerticalAlignment="Top"  Height="33" Width="137"/><Label x:Name="Label2" ContentStringFormat="{}{0:d}" Content="{Binding  Path=FirstDecember2K}"  HorizontalAlignment="Left" Margin="177,146,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.096,0.59"/><Label x:Name="Label3" Content="{Binding Path=FirstDecember2K, Converter={StaticResource DateTimeConverterRes}}" HorizontalAlignment="Left" Margin="177,225,0,0" VerticalAlignment="Top"/></Grid></Window>

and here is the C# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Globalization ;

namespace DateCulture
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();
			DataContext = this ;
		}
		public DateTime FirstDecember2K {get ; set ; } = new DateTime( 2000, 12, 1) ;
	}


	public class DateTimeToString : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			string RetVal = "Unknown" ;

			if ( value is DateTime)
			{
				RetVal = ((DateTime)value).ToString( "d") ;
			}
			return ( RetVal ) ;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}

The resulting application looks as follows:

Application screen shot showing dates

As can be seen:

  • Label1: With no formatting given, the current culture is totally ignored and the date is shown in USA format.
  • Label2: When the date is formatted using ":d", which shouldformat the date in the current culture, the culture is still ignored.
  • Label3: Uses a rather long winded way to format the date, but at least it comes out respecting the current culture.

Now I am sure that I must be missing something obvious, because it really should not be so awkward to get a WPF application to respect the current culture. Assuming there is an easy way, can anyone tell me how to do it please?

(For background information, my real life application is displaying a data grid, with one of the columns being a date stamp, I would hope that any solution that works for a label would also work for a data grid.)

Thanks in advance.

Andrew Ch.

Socket stops to connect after several attempts

$
0
0

Hi. I have recently developed client and server applications that works via TCP. Sometimes the client application lost connection, so I make it reconnect to server(I've heared about Keepalive, but due to lack of time haven't google it). the problem is that client connects - lose connection after a while - connects - lose connectin after a while - tries to connect and get exception "Host hasn't responed after a perioud of time" or something like this. I've debuged server and found that server just have no attempt of connection. I've tried to create new socket(_socket = new Socket();) and connect via it(unsuccessfuly). The only thing that helped - was restart of application. So my questions are:

- What could be the reason that client stops connecting? 

- How can i fix it?

Excel 365 School

$
0
0
I have a personal account and school account for Microsoft. The school account (Microsoft 365) enables me to edit excel files when opening file on an Ipad... I have been able to open the school account on the Ipad but on my computer it only allows me to open my personal account. How can I access my School account also on my computer?

Image Scaling to Real World Measurements

$
0
0

Hi,

I'm displaying a JPEG image that is 4000 x 3000 pixels in size. The image is loaded into a bitmap and displayed inside an image control. The window containing the image is maximized, but may be resized. On a 1600 x 1200 monitor the image is obviously scaled down in both the X and Y directions. I get scaling factors by comparing the actual width and height of the image vs. the display size of the image (the image control's width and height).  I move the cursor around the image to known points in the image. I take the cursor position and convert it to the image position to hopefully get the known points “true” location. The calculation works fine for points near the center of the image. However at the top and bottom of the screen the scale factor does not work. It is too large for points close to the top of the image and too small for points at bottom.  

Any suggestions as to what my issue might be?

Thanks.

How to implement Data Virtualization for listbox to generate thumbnails

$
0
0

Hi,

We are developing our application by using WPF and C#. Our requirement is to load all the files from the selected directory and display those file in listbox. For us listbox each item template is Image control. We are using BitmapSource type property in a CS class and this property is binded to Image control Source property in Xaml part.

We want to genarate thumbnails for these images in listbox on scroll basis. On each scrool we need to generate thumbnail for all items which comes into view, and also we should unload memory for previously displays thumbnails which goes out from view due to current scrool. when we scroll back to previous position then again those items should be reloaded.
So that fixed memory is used to view all the images.

Please give some suggestion to achieve this ?

How to SelectAll in TextBox when TextBox gets focus by mouse click?

$
0
0

If you click into the adress bar of the internet explorer, the adress will get selected. Only the second click sets the caret into the mouse position.

 

I'd like to have this in my TextBox. I tried to override OnGotFocus and call SelectAll(), but this only works if the TextBox gets it focus by keyboard. If the TextBox is clicked by mouse, the text is selected for a split second, then it is deselected again and the caret is set.

 

Thanks,
Sam


application with layer mask and transparency.

$
0
0

I'm trying to create an application that has a cropped shape with a bitmap image of 2 colors and that allows to create very fine cuts and also transparency I will attach an image so that they understand me as I want it and how is that for now I can do it, if someone has any solution please I appreciate your interest to help me.

https://1drv.ms/u/s!Ar8ellvD30gKqm9j7kFXro0azWM6


how can I swap 2 buttons which are in the same grid

$
0
0

hi, I am new to c# wpf, I have a grid which contains some buttons, now I want to make a swap button position function, like drag any 1 button and drop it to another button's position, then the other 1 will replace to the first buttons position. how can I do that? here is the code how do I draw the grid and generate buttons.

in XAML fies

    <Grid x:Name="BtnGrid">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        </Grid>

in Cs file


        public MainWindow()
        {
            InitializeComponent();
            int count = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    Button btn = new Button();
                    btn.Margin = new Thickness(1);
                    Grid.SetColumn(btn, j);
                    Grid.SetRow(btn, i);

                    count++;
                    btn.Name = "btn" + Convert.ToString(count);
                    btn.Content = btn.Name;
                    BtnGrid.Children.Add(btn);
                }
            }
        }

Use MediaPlayer to open an online video of https protocol failed

$
0
0

it can be successed to open a "http" video,but "https" is failed.

code:

MediaPlayer player=new MediaPlayer();

player.Open(new Uri(@"https://www.musictime-studio.com/webfile/musical_demo/20180730045604.mp3", UriKind.Absolute));

exception:System.NullReferenceException;

anyone who can help me!!

How to use XAML to share some of the properties of multiple TextBlocks

$
0
0

Is there a standard way in XAML to collect similarly derived properties with the same values from several controls into one place?

What is the best way to do it?

The code below demonstrates the functionality I am thinking of with WPF TextBlocks, although it doesn't do what I want. It ignores the Canvas.Left and Canvas.Top property values and concatenates each successive fragment of text (starting at Left,Top=0,0).

Canvas.Left,Top are what the designer used in <TextBlocks>—lines which I duplicated and reformatted into the below. I didn't see any x, y properties in class TextBlock itself. (Perhaps I simply should be using something other than Canvas.Left, Top for the TextBlocks' x,y?)

<local:DrawingWindow x:Class="MyApp.WelcomeScreen"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:local="clr-namespace:MyApp"
    mc:Ignorable="d" 
    d:DesignHeight="500" d:DesignWidth="500"
    Background="Black"
    Margin="1,1,1,1">
    <TextBlock Foreground="Orange" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="350" FontFamily="FreeSans" FontSize="14">
        <TextBlock Canvas.Left="100" Canvas.Top="100" Text="Now is the time\nfor all good men"/>
        <TextBlock Canvas.Left="120" Canvas.Top="150" Text="to come to"/>
        <TextBlock Canvas.Left="140" Canvas.Top="200" Text="the aid of their country."/>
    </TextBlock>
</local:DrawingWindow>

-Mrutyunjaya

Possible FocusVisualStyle bug for ComboBox in Aero2 theme

$
0
0

Prior to the introduction of the Aero2 theme, the focus visual for an unexpanded ComboBox would appear around the content, and wouldnot encompass the arrow at the right hand side of the ComboBox.

This was achieved with a FocusVisualStyle looking like this:

<Style x:Key="ComboBoxFocusVisual"><Setter Property="Control.Template"><Setter.Value><ControlTemplate><Rectangle Margin="4,4,21,4"
                    StrokeThickness="1"
                    Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
                    StrokeDashArray="1 2"
                    SnapsToDevicePixels="true"/></ControlTemplate></Setter.Value></Setter></Style>
In Aero2, although the theme resource dictionary still seems to contain an identical Style, it is no longer used. The default theme style for ComboBox now uses {StaticResource FocusVisual} instead of {StaticResource ComboBoxFocusVisual}. So the relevant focus visual style is still in the dictionary, it's just not used.

That 'FocusVisual' style is the same one used by buttons, list box items and so on, all of which get a focus rectangle drawn around all of their content.

So this change in Aero2 brings the ComboBox in line with all the other controls.

However, Windows 10 itself does not do this. If you look at a Win32 ComboBox, you'll find that its focus outline continues to be drawn around just the content, excluding the arrow to the right. The upshot of this is a (subtle) inconsistency between WPF applications and Win32 applications when running on Windows 10.

So I think this is probably a bug.

Bind data to Class

$
0
0
Hoping to get some help.
I'm in the process of creating a printfunction using C# and the Autodesk Revit APi. I downloaded the revit SDK and found a sample called ViewPrinter. I learned a lot from it, and I want to use some of it. Especially the PrintMgr class, which is based on the build-in class  (Autodesk.Revit.DB.)PrintManager.  Slight hickup is that it's winform based and i'm using WPF.
This class PrintMgr uses

public PrintMgr(ExternalCommandData commandData)

{

m_commandData = commandData;

m_printMgr = commandData.Application.ActiveUIDocument.Document.PrintManager;

}



to assign the current Printmanager to m_printMgr. as you can see it uses 
commandData

to do it.
The only place i know where commandData is available, is at the EntryPoint (which in my case is in PrintWindowModel ):

public Autodesk.Revit.UI.Result Execute(

ExternalCommandData commandData,

ref string message, Autodesk.Revit.DB.ElementSet elements)



So i created an instance of PrintMgr (called PrintManager) here. But, and here comes my problem:
How do I bind any data to this class?   I've set 
datacontext=PWM 

  (PWM= begin an instance of PrintWindowModel)
I tried

text="{Binding PrintManager.PrinterName}"

<!--Where PrinterName is a property of PrintManager ofcourse-->





But that doesn't work. 
So I guess it comes down to the question:
How do I set a databinding to an instance of a Class, which is instantiated in my datacontext?

Cropping when moving and resizing a cropping rectangle

$
0
0

I created a program that crops an image and displays the cropped image but I'm trying to add more functionality by making it movable and resizable.

The rectangle moves and resizes but it only crops an image when user draws the rectangle and not when moved or resized. I know that the X,Y, height and width position of the rectangle would need to be updated but I'm not sure how I can accomplish this being new to WPF. Below is my user control "CropControl and the code behind. Also, I'm implementing my code using MVVM framework. 

<UserControl x:Class="Klein_Tools_Profile_Pic_Generator.CropControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:s="clr-namespace:Klein_Tools_Profile_Pic_Generator"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}">
            <Rectangle Fill="Transparent"/>
        </ControlTemplate>

        <!-- ResizeDecorator Template -->
        <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
            <Grid>
                <s:ResizeThumb Width="3" Height="7" Cursor="SizeNS" Margin="0 -4 0 0"
                       VerticalAlignment="Top"/>
                <s:ResizeThumb Width="3" Height="7" Cursor="SizeWE" Margin="-4 0 0 0"
                       VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="3" Height="7" Cursor="SizeWE" Margin="0 0 -4 0"
                       VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
                <s:ResizeThumb Width="3" Height="7" Cursor="SizeNS" Margin="0 0 0 -4"
                       VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE"
                       VerticalAlignment="Top" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" 
                       VerticalAlignment="Top" HorizontalAlignment="Right"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNESW"                        
                       VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                <s:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" 
                       VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
            </Grid>
        </ControlTemplate>

        <!-- Designer Item Template-->
        <ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
            <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                <s:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
                <Control Template="{StaticResource ResizeDecoratorTemplate}"/>
                <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
            </Grid>
        </ControlTemplate>
        
    </UserControl.Resources>
    <Canvas x:Name="BackPanel"
            MouseLeftButtonDown="LoadedImage_MouseLeftButtonDown" 
            MouseMove="LoadedImage_MouseMove" 
            MouseLeftButtonUp="LoadedImage_MouseLeftButtonUp"
            Background="Transparent">
        <ContentControl x:Name="contControl" Visibility="Collapsed"
                        Template="{StaticResource DesignerItemTemplate}">
            <Rectangle x:Name="selectionRectangle" Fill="#220000FF" 
                IsHitTestVisible="False"/>
        </ContentControl>
    </Canvas>
</UserControl>



Code Behind:
     namespace Klein_Tools_Profile_Pic_Generator
    {
    /// <summary>
    /// Interaction logic for CropControl.xaml
    /// </summary>

    public partial class CropControl : UserControl
    {
        private bool isDragging = false;
        private Point anchorPoint = new Point();
        private bool moveRect;
        TranslateTransform trans = null;
        Point originalMousePosition;
        public CropControl()
        {
            InitializeComponent();

        }

        //Register the Dependency Property
        public static readonly DependencyProperty SelectionProperty =
            DependencyProperty.Register("Selection", typeof(Rect), typeof(CropControl), new PropertyMetadata(default(Rect)));

        public Rect Selection
        {
            get { return (Rect)GetValue(SelectionProperty); }
            set { SetValue(SelectionProperty, value); }
        }

        // this is used, to react on changes from ViewModel. If you assign a  
        // new Rect in your ViewModel you will have to redraw your Rect here
        private static void OnSelectionChanged(System.Windows.DependencyObject d,             System.Windows.DependencyPropertyChangedEventArgs e)
        {
            Rect newRect = (Rect)e.NewValue;
            Rectangle selectionRectangle = d as Rectangle;

            if (selectionRectangle != null)
                return;

            selectionRectangle.SetValue(Canvas.LeftProperty, newRect.X);
            selectionRectangle.SetValue(Canvas.TopProperty, newRect.Y);
            selectionRectangle.Width = newRect.Width;
            selectionRectangle.Height = newRect.Height;
        }

        private void LoadedImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (isDragging == false)
            {
                anchorPoint.X = e.GetPosition(BackPanel).X;
                anchorPoint.Y = e.GetPosition(BackPanel).Y;
                Canvas.SetZIndex(selectionRectangle, 999);
                isDragging = true;
                BackPanel.Cursor = Cursors.Cross;
            }

        }

        private void LoadedImage_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                double x = e.GetPosition(BackPanel).X;
                double y = e.GetPosition(BackPanel).Y;
                contControl.SetValue(Canvas.LeftProperty, Math.Min(x, anchorPoint.X));
                contControl.SetValue(Canvas.TopProperty, Math.Min(y, anchorPoint.Y));
                contControl.Width = Math.Abs(x - anchorPoint.X);
                contControl.Height = Math.Abs(y - anchorPoint.Y);

                if (contControl.Visibility != Visibility.Visible)
                    contControl.Visibility = Visibility.Visible;

            }
        }

        private void Image_MouseMove(object sender, MouseEventArgs e)
        {
            if (moveRect)
            {
                trans = selectionRectangle.RenderTransform as TranslateTransform;
                if (trans == null)
                {
                    selectionRectangle.RenderTransformOrigin = new Point(0, 0);
                    trans = new TranslateTransform();
                    selectionRectangle.RenderTransform = trans;
                }
                trans.Y = -(originalMousePosition.Y - e.GetPosition(BackPanel).Y);
                trans.X = -(originalMousePosition.X - e.GetPosition(BackPanel).X);
            }
            e.Handled = false;
        }

        private void LoadedImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (isDragging)
            {
                isDragging = false;
                if (contControl.Width > 0)
                {
                    //Crop.IsEnabled = true;
                    //Cut.IsEnabled = true;
                    BackPanel.Cursor = Cursors.Arrow;
                }

                contControl.GetValue(Canvas.LeftProperty);
                // Set the Selection to the new rect, when the mouse button has been released
                Selection = new Rect(
                    (double)contControl.GetValue(Canvas.LeftProperty),
                    (double)contControl.GetValue(Canvas.TopProperty),
                    contControl.Width,
                    contControl.Height);

            }
        }
        
    }
}

--Mrutyunjaya


Reference on UIElement

$
0
0

When I Create MVVM in view I can Write 1 string DataContext=new ViewModel();

My Class ViewModel Have property refer to control on View on example LbMaxim

How I Can bound my property LbMaxim in Constructor ViewModel?

public class ViewModel
    {

  internal controls::ListBox LbMaxim { get; set; }

}

How to get the user control values to main window in wpf using mvvm pattern

$
0
0

I have 4 text boxes in user control 

In my mainwindow.xaml

    I will be clicking an add button so that my user control and another add button will be visible. 

     Here I have entered all the values in the text boxes I.e in my user control how to send those values to my view model.

DependencyProperty RegisterAttached working on keypress but I need it on context menu click

$
0
0

Working on Data grid Copy, Cut, Paste and Completed with Dependency Property Register Attached.

Problem is on  Key press  its working Fine, Now I need same behavior in Context Menu Also..

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using Clipboard = System.Windows.Clipboard;
using DataGrid = System.Windows.Controls.DataGrid;
using MessageBox = System.Windows.MessageBox;
using TextDataFormat = System.Windows.TextDataFormat;

namespace GUI.Model
{
  
    public  class Cutcopypaste 
    {
        
        public static DependencyProperty CopyPasteProperty = DependencyProperty.RegisterAttached("CopyPaste",
            typeof(bool), typeof(Cutcopypaste),
            new FrameworkPropertyMetadata(false, Onpropertychanged));


        private static readonly CommandBinding BindingPaste =
            new CommandBinding(ApplicationCommands.Paste, CommandBinding_CanExecutePaste);


        private static readonly CommandBinding BindingCut =
            new CommandBinding(ApplicationCommands.Cut, CommandBinding_CanExecuteCut);


        private static readonly CommandBinding BindingDelete =
            new CommandBinding(ApplicationCommands.Delete, CommandBinding_CanExecuteDelete);

        private static void CommandBinding_CanExecuteCut(object sender, ExecutedRoutedEventArgs e)
        {         
        //something
        }
        

        private static async void CommandBinding_CanExecutePaste(object sender, ExecutedRoutedEventArgs e)
        {
           //something
           
        }

        private static async void CommandBinding_CanExecuteDelete(object sender, ExecutedRoutedEventArgs e)
        {
            //something
        }

     

        private static void Onpropertychanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var datagrid = (DataGrid) d;
            datagrid.CommandBindings.Add(BindingPaste);
            datagrid.CommandBindings.Add(BindingCut);
            datagrid.CommandBindings.Add(BindingDelete);
            
        }


        public static bool GetCopyPaste(DependencyObject target)
        {
            return (bool) target.GetValue(CopyPasteProperty);
        }

        public static void SetCopyPaste(DependencyObject target, bool value)
        {
            target.SetValue(CopyPasteProperty, value);
        }

        
    }
}
<DataGrid x:Name="WelcomeDatagrid1" ItemsSource="{Binding Dt}" ccp:Cutcopypaste.CopyPaste="True"  HeadersVisibility="All"<DataGrid.ContextMenu><ContextMenu><MenuItem Header="Cut" InputGestureText="Ctrl+X"  Command="ApplicationCommands.Copy" ></MenuItem><MenuItem Header="Copy" InputGestureText="Ctrl+C" Command="ApplicationCommands.Copy" CommandParameter="Copy"></MenuItem><MenuItem Header="Paste" InputGestureText="Ctrl+V" Command="ApplicationCommands.Paste"></MenuItem><MenuItem Header="Delete"  Command="{x:Static ccp:Cutcopypaste.DatagridContextCommand}" CommandParameter="BindingDelete"></MenuItem></ContextMenu></DataGrid.ContextMenu></DataGrid>

Problem Statement:

Context Menu should call  Copy, Cut, Paste from Dependency Property Register Attached.


How to create validation inside a custom datagrid control in wpf

$
0
0

Hai

I want to validate inside my custom datagrid

Something like this

    public class IGrid : DataGrid
    {
        static bool HasError;
    }
    public class DataGridTextcolumn : DataGridTextColumn
    {
        public DataGridTextcolumn()
        {

        }
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox textBox = sender as TextBox;
            string newText = textBox.Text;
            if (newText == "xxx")
            {
                IGrid.HasError = true;
            }
            else
            {
                IGrid.HasError = false;
            }
        }
    }
Please help me 

How to validate  the cell using ValidationRule with HasError variable.

Thanks.


programmer

Databinding clears combobox value on datacontext switch

$
0
0

Hello.

 I have a ListBox, which is databounded to an collection of MyGarage classes. On the SelectionChanged I change the Window's DataContext to the selected MyGarage class.

 

 MyGarage has a ObservableCollection of Cars and a SelectedCar property.

 

 There is a a ComboBox, which is bounded to the SelectedCar property.

 

 Now, if I change the selection in ListBox, in the DataContext = ItemsBox.SelectedItem as MyGarage statement, External code sets SelectedCar of the curent MyGarage class to the null.

 

 Why and how to avoid this?

Viewing all 18858 articles
Browse latest View live


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