xaml

WPF - How to get canvas position on mouse click independently of the resolution and resizing

北城以北 提交于 2021-02-05 11:12:47
问题 I found a lot on this subject for HTML 5 JavaScript (like so), but I have found nothing over WPF. I have a canvas that we are creating for selecting points over a image in that canvas. The canvas element in XAML is very simple: <Canvas x:Name="Cnv" Grid.Column="1" Grid.Row="1" /> We are getting the coordinates from mouse click like so: Point p = Mouse.GetPosition(Cnv); Then, we draw something on that point: ellipse = new Ellipse(); ellipse.Fill = Brushes.Transparent; ellipse.Width = 20;

WPF - How to get canvas position on mouse click independently of the resolution and resizing

扶醉桌前 提交于 2021-02-05 11:12:01
问题 I found a lot on this subject for HTML 5 JavaScript (like so), but I have found nothing over WPF. I have a canvas that we are creating for selecting points over a image in that canvas. The canvas element in XAML is very simple: <Canvas x:Name="Cnv" Grid.Column="1" Grid.Row="1" /> We are getting the coordinates from mouse click like so: Point p = Mouse.GetPosition(Cnv); Then, we draw something on that point: ellipse = new Ellipse(); ellipse.Fill = Brushes.Transparent; ellipse.Width = 20;

WPF - How to get canvas position on mouse click independently of the resolution and resizing

我与影子孤独终老i 提交于 2021-02-05 11:11:56
问题 I found a lot on this subject for HTML 5 JavaScript (like so), but I have found nothing over WPF. I have a canvas that we are creating for selecting points over a image in that canvas. The canvas element in XAML is very simple: <Canvas x:Name="Cnv" Grid.Column="1" Grid.Row="1" /> We are getting the coordinates from mouse click like so: Point p = Mouse.GetPosition(Cnv); Then, we draw something on that point: ellipse = new Ellipse(); ellipse.Fill = Brushes.Transparent; ellipse.Width = 20;

WPF - How to get canvas position on mouse click independently of the resolution and resizing

三世轮回 提交于 2021-02-05 11:11:03
问题 I found a lot on this subject for HTML 5 JavaScript (like so), but I have found nothing over WPF. I have a canvas that we are creating for selecting points over a image in that canvas. The canvas element in XAML is very simple: <Canvas x:Name="Cnv" Grid.Column="1" Grid.Row="1" /> We are getting the coordinates from mouse click like so: Point p = Mouse.GetPosition(Cnv); Then, we draw something on that point: ellipse = new Ellipse(); ellipse.Fill = Brushes.Transparent; ellipse.Width = 20;

WPF - How to get canvas position on mouse click independently of the resolution and resizing

天涯浪子 提交于 2021-02-05 11:10:14
问题 I found a lot on this subject for HTML 5 JavaScript (like so), but I have found nothing over WPF. I have a canvas that we are creating for selecting points over a image in that canvas. The canvas element in XAML is very simple: <Canvas x:Name="Cnv" Grid.Column="1" Grid.Row="1" /> We are getting the coordinates from mouse click like so: Point p = Mouse.GetPosition(Cnv); Then, we draw something on that point: ellipse = new Ellipse(); ellipse.Fill = Brushes.Transparent; ellipse.Width = 20;

Give a name and declare event handler of a button Created at run time with C# XamlReader

冷暖自知 提交于 2021-02-05 09:43:44
问题 I am working on a project in C# and WPF that dynamically creates a grid layout that has some text, an image, and a button. I create many of these grids, and add them to a stack panel. I create this grid using the XamlReader.Create() function. Here is the whole code, and i apologize that the Xaml code is so long string xaml = "<Grid Height='92' Margin='0,10,0,0' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>"+ "<Grid.Background>"+ "<LinearGradientBrush EndPoint='0.5,1'

WPF binding Listbox SelectedItem in ViewModel

南楼画角 提交于 2021-02-05 09:34:46
问题 I'm working on a WPF application. The main page is made up of a grid with 2 column and one row. on the first column i have a listbox and on the 2nd column i have a stackpanel named thePanel which i want to change on selected item of a listbox.i first implemented this in the View(mainwindow.xaml.cs) with the selectionChanged event of the Listbox and it worked. I tried to apply the MVVM so i had to do it in the viewModel. the Data Context of the mainwindow is set in its constructor and is of

WPF: Binding to MainWindow Property

隐身守侯 提交于 2021-02-05 08:46:26
问题 I am having an issue with binding to a parent MainWindow property, MainContentVisibility. I have the following code: MainWindow.xaml <Window x:Class="CallTracker.WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:v="clr-namespace:MyProgram.WPF.Views" DataContext="{Binding MainPageViewModel, Source={StaticResource Locator}}"> <StackPanel> <v:CompanyInfoUserControl Width="800" Visibility="{Binding MainContentVisibility, RelativeSource={RelativeSource Mode

Getting selected Item in DataGrid in WPF

与世无争的帅哥 提交于 2021-02-05 08:33:26
问题 I have a datagrid and textboxes. When I select a row in DataGrid I want the textboxes to be filled with related data of that datagrid column. Here is the picture., I have written this code in MainWindow.xaml.cs : private void personelEntityDataGrid_Loaded(object sender, RoutedEventArgs e) { PersonelEntity pers = (PersonelEntity)personelEntityDataGrid.SelectedItem; NameBox.Text = pers.Name; // I get exception here AgeBox.Text = pers.Age.ToString(); PhoneNumberBox.Text = pers.PhoneNumber;

Textblock in Viewbox not multiline

柔情痞子 提交于 2021-02-05 07:59:05
问题 I'm having a bit of a trouble with the autosizing of a text. I read somewhere that if I wanted to achieve that, i need to put my textblock in a viewbox . The problem with that is this way the text isn't split into multiple lines. For example "very very very long text" is almost unreadable, but "simpletext" looks just fine. <Viewbox Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="4" StretchDirection="DownOnly"> <TextBlock Text="{Binding FieldName}" VerticalAlignment="Center"