# C1.WPF.Extensions.SetBinding

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_WPF_Extensions_SetBinding_" data-uid="C1.WPF.Extensions.SetBinding*">SetBinding Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_WPF_Extensions_SetBinding_" data-uid="C1.WPF.Extensions.SetBinding*"></a>
<h4 id="C1_WPF_Extensions_SetBinding__1_System_Windows_FrameworkElement_System_Windows_DependencyProperty___0_System_Linq_Expressions_Expression_System_Func___0_System_Object___" data-uid="C1.WPF.Extensions.SetBinding``1(System.Windows.FrameworkElement,System.Windows.DependencyProperty,``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}})">SetBinding&lt;T&gt;(FrameworkElement, DependencyProperty, T, Expression&lt;Func&lt;T, object&gt;&gt;)</h4>
<div class="markdown level1 summary"><p>Sets the binding if the dependency property has not been set previously and the style of the element don't set the property.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static void SetBinding&lt;T&gt;(this FrameworkElement target, DependencyProperty dp, T source, Expression&lt;Func&lt;T, object&gt;&gt; expr)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Sub SetBinding(Of T)(target As FrameworkElement, dp As DependencyProperty, source As T, expr As Expression(Of Func(Of T, Object)))</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a></td>
      <td><span class="parametername">target</span></td>
      <td><p>The target.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.dependencyproperty">DependencyProperty</a></td>
      <td><span class="parametername">dp</span></td>
      <td><p>The dependency property which will be set.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">T</span></td>
      <td><span class="parametername">source</span></td>
      <td><p>The source.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;T, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a>&gt;&gt;</td>
      <td><span class="parametername">expr</span></td>
      <td><p>Expression that returns a property of the source object.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">T</span></td>
      <td><p>Type of the source</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_WPF_Extensions_SetBinding_" data-uid="C1.WPF.Extensions.SetBinding*"></a>
<h4 id="C1_WPF_Extensions_SetBinding__1_System_Windows_FrameworkElement_System_Windows_DependencyProperty___0_System_Linq_Expressions_Expression_System_Func___0_System_Object___System_Windows_Data_IValueConverter_" data-uid="C1.WPF.Extensions.SetBinding``1(System.Windows.FrameworkElement,System.Windows.DependencyProperty,``0,System.Linq.Expressions.Expression{System.Func{``0,System.Object}},System.Windows.Data.IValueConverter)">SetBinding&lt;T&gt;(FrameworkElement, DependencyProperty, T, Expression&lt;Func&lt;T, object&gt;&gt;, IValueConverter)</h4>
<div class="markdown level1 summary"><p>Sets the binding if the dependency property has not been set previously and the style of the element don't set the property.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public static void SetBinding&lt;T&gt;(this FrameworkElement target, DependencyProperty dp, T source, Expression&lt;Func&lt;T, object&gt;&gt; expr, IValueConverter converter)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Shared Sub SetBinding(Of T)(target As FrameworkElement, dp As DependencyProperty, source As T, expr As Expression(Of Func(Of T, Object)), converter As IValueConverter)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a></td>
      <td><span class="parametername">target</span></td>
      <td><p>The target.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.dependencyproperty">DependencyProperty</a></td>
      <td><span class="parametername">dp</span></td>
      <td><p>The dependency property which will be set.</p>
</td>
    </tr>
    <tr>
      <td><span class="xref">T</span></td>
      <td><span class="parametername">source</span></td>
      <td><p>The source.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.linq.expressions.expression-1">Expression</a>&lt;<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.func-2">Func</a>&lt;T, <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a>&gt;&gt;</td>
      <td><span class="parametername">expr</span></td>
      <td><p>Expression that returns a property of the source object.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.data.ivalueconverter">IValueConverter</a></td>
      <td><span class="parametername">converter</span></td>
      <td><p>The converter that will be applied to the created binding object.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><span class="parametername">T</span></td>
      <td><p>Type of the source</p>
</td>
    </tr>
  </tbody>
</table>
</div>
