---
title: "Bind XAML property indirectly"  
description: "Bind XAML property indirectly"  
author: "Samuel Fernandes"  
published: 2013-09-23  
updated: 2013-09-23  
canonical: https://www.mindstick.com/forum/1495/bind-xaml-property-indirectly  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# Bind XAML property indirectly

Imagine, I have a [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) and a [binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp):

<Button [Content](https://www.mindstick.com/articles/13019/get-the-best-content-marketing-pricing-packages-for-your-brand)="{Binding Path=FailOverStrings.ConfigTestBtn, [Source](https://www.mindstick.com/interview/840/what-happens-if-the-both-source-and-destination-are-named-same)={StaticResource ResourceWrapper}}></Button>

**Now I want to [setup](https://www.mindstick.com/articles/426/how-to-create-a-setup-project-for-windows-application) an array of such buttons:**

```
        <Grid >            <ItemsControl>               
<ItemsControl.ItemTemplate>                   
<DataTemplate>                       
<Grid>                           
<Button Content="{Binding Title}" />                       
</Grid>                   
</DataTemplate>               
</ItemsControl.ItemTemplate>           
</ItemsControl>        </Grid>
```

I will create a [collection](https://www.mindstick.com/articles/1718/collections-in-java) in the [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind) but how to say that '[Title](https://www.mindstick.com/articles/12860/how-to-get-financing-for-salvage-title-cars)' which is equal to 'ConfigTestBtn' is not really a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) 'ConfigTestBtn' itself but is a name of a [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) of FailOverStrings ?

Some kind of an indirection in binding. I suppose I can write a converter to do it, but is it really necessary?

## Replies

### Reply by Pravesh Singh

Hi Samuel,

Suppose you have a class like below.

```
public class FailOverStrings{    public FailOverStrings()    {        ConfigTestBtn = "Actual value";    }    public string ConfigTestBtn { get; set; }}
```

Then your converter can look like this \

```
public class PropertNameToValueConverter : IValueConverter{    public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)    {        string retValue = string.Empty;       
FailOverStrings settings = new FailOverStrings();       
foreach(PropertyInfo pinfo in settings.GetType().GetProperties())        {            if (pinfo.Name == value.ToString())            {               
       retValue = pinfo.GetValue(settings, null).ToString();            }        }        return retValue;    }    public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)    {        throw new NotImplementedException();    }}
```

And using this converter in button like this

```
<Window.Resources>    <local:PropertNameToValueConverter x:Key="PropertNameToValueConverter"></local:PropertNameToValueConverter></Window.Resources><Grid>    <Button
Content="{Binding ElementName=myWindow, Path=PropertyName, Converter={StaticResource ResourceKey=PropertNameToValueConverter}}"
Width="100" Height="30" /></Grid>
```


---

Original Source: https://www.mindstick.com/forum/1495/bind-xaml-property-indirectly

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
