How to get XY coordinates of a control at runtime in WPF? [duplicate]

For that, there is the TransformToAncestor method: Point relativePoint = myVisual.TransformToAncestor(rootVisual) .Transform(new Point(0, 0)); Where myVisual is the element you want to get the position of, and rootVisual is Application.Current.MainWindow or whatever you want the position relative to. reference link: Get Absolute Position of element within the window in wpf

What is the simplest way to get the selected text of a combo box containing only text entries?

In your xml add SelectedValuePath=”Content” <ComboBox Name=”cboPickOne” SelectedValuePath=”Content” > <ComboBoxItem>This</ComboBoxItem> <ComboBoxItem>should be</ComboBoxItem> <ComboBoxItem>easier!</ComboBoxItem> </ComboBox> This way when you use .SelectedValue.ToString() in the C# code it will just get the string value without all the extra junk: stringValue = cboPickOne.SelectedValue.ToString()

Avoiding Visual Studio designer errors when WPF resource is defined in separate project

You could create your own ResourceDictionary class, inheriting from ResourceDictionary. Then you can arrange that at design-time this custom ResourceDictionary loads some explicitly defined styles (i.e. those loaded from the app at runtime), whereas at runtime it does nothing at all. The IsInDesignMode-Property could be evaluated for this. Say you have such a class, called … Read more

How to bind DataTemplate datatype to interface?

You can bind to interfaces by telling wpf explicitly that you are binding to an interface field: (Please note that ViewModelBase is simply a base-class that implements the INotifyPropertyChanged interface) public class Implementation : ViewModelBase, IInterface { private string textField; public string TextField { get { return textField; } set { if (value == textField) … Read more

Binding in WPF to element of array specified by property

Another alternative is to use MultiBinding with a converter: <Window x:Class=”WpfApplication1.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:local=”clr-namespace:WpfApplication1″ Title=”MainWindow” Height=”350″ Width=”525″> <StackPanel Orientation=”Vertical”> <StackPanel.Resources> <local:FoodIndexConverter x:Key=”foodIndexConverter” /> </StackPanel.Resources> <TextBlock Text=”{Binding DessertIndex}” /> <TextBlock Text=”{Binding Food[2]}” /> <TextBlock> <TextBlock.Text> <MultiBinding Converter=”{StaticResource foodIndexConverter}”> <Binding Path=”DessertIndex” /> <Binding Path=”Food”/> </MultiBinding> </TextBlock.Text> </TextBlock> </StackPanel> </Window> Then in the code-behind, the converter is defined … Read more

WPF DataGrid RowHeader databinding

I tried both answers, and neither worked for me. Essentially what I had to do was mix them together. This works for me: <DataGrid name=”ui_dataGrid> <DataGrid.RowHeaderTemplate> <DataTemplate> <TextBlock Text=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Path=Item.Header}”/> </DataTemplate> </DataGrid.RowHeaderTemplate> </DataGrid> The trick is to find the ancestor DataGridRow, then Bind the TextBlock.Text attribute to its Item’s property that … Read more

How to bind local property on control in WPF

Try: Content=”{Binding ElementName=_this, Path=CompanyName}” Without the DataContext binding. EDIT I have no problems with your code, have named your window to x:Name=”_this”? <Window x:Class=”WpfStackOverflowSpielWiese.Window3″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”Window3″ Height=”300″ Width=”300″ x:Name=”_this”> <Grid> <StackPanel> <Button HorizontalAlignment=”Center” Name=”btnChange” Click=”btnChange_Click” Content=”Click Me” /> <Label Name=”lblCompanyId” HorizontalAlignment=”Center” DataContext=”{Binding ElementName=_this}” Content=”{Binding Path=CompanyName}”></Label> </StackPanel> </Grid> </Window> Is your window really Window3? public … Read more