c# - How to Bind a textBlock's value with another TextBlocks value In the same window? -


please picture below. 1 window have placed multiple textblocks inside grid. marketing team compelled me design ui this. facing other issues like

i have code xaml can achieve ui design if place textblocks in way.

 <textblock x:name="bluetextblock"           margin="100,10,0,0"           foreground="blue"           text="{binding elementname=gridalltextblocks, path=???   mode=twoway}"/>    <grid x:name="gridalltextblocks">              <grid.rowdefinitions>           <rowdefinition height="40" />           <rowdefinition height="40" />           <rowdefinition height="40" />           <rowdefinition height="40" />                                </grid.rowdefinitions>       <grid.columndefinitions>           <columndefinition width="*" />           <columndefinition width="*" />           <columndefinition width="*" />      </grid.columndefinitions>       <textblock grid.row="0" grid.column="0" focusable="true" text="value 1"/>      <textblock grid.row="1" grid.column="0" focusable="true" text="value 6"/>      <textblock grid.row="2" grid.column="1" focusable="true" text="value 2"/>      <textblock grid.row="3" grid.column="3" focusable="true" text="value 3"/>      <textblock grid.row="1" grid.column="1" focusable="true" text="value 4"/>      <textblock grid.row="2" grid.column="3" focusable="true" text="value 5"/>  </grid> 

now question is: how bind value of bluetextblock 1 of value of textblocks inside grid.

lets have selected textblock having text="value 2" bluetextblock text should value 2.

how can achieve this?

here complete solution need... easy have selection selected item style removed override listview.itemcontainerstyle

<window x:class="wpfapplication1.gridview"     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:wpfapplication1"     mc:ignorable="d"     title="listview" height="600" width="800"> <grid>     <grid.rowdefinitions>         <rowdefinition height="auto"/>         <rowdefinition height="3"/>         <rowdefinition height="*"/>     </grid.rowdefinitions>     <textblock foreground="blue" height="45" grid.row="0" margin="10" text="{binding elementname=listview, path=selecteditem}" fontsize="20"/>     <rectangle grid.row="1" fill="gray" margin="10 0"/>     <listview x:name="listview"  grid.row="2" scrollviewer.horizontalscrollbarvisibility="disabled" itemssource="{binding items}" foreground="green" fontsize="20" grid.issharedsizescope="true" borderthickness="0">         <listview.itemtemplate>             <datatemplate>                 <grid>                     <grid.columndefinitions>                         <columndefinition sharedsizegroup="group" width="150"/>                     </grid.columndefinitions>                     <textblock text="{binding}" fontsize="20" foreground="green" horizontalalignment="center"/>                 </grid>             </datatemplate>         </listview.itemtemplate>         <listview.itemspanel>             <itemspaneltemplate>                 <wrappanel orientation="horizontal"/>             </itemspaneltemplate>         </listview.itemspanel>     </listview> </grid> </window> 

the result

first of textblock not selectable... if have control can selected instance combobox

you can of following

text="{binding elementname=comboboxname, path=selecteditem.property}"

<textblock text="{binding elementname=box1, path=selecteditem.property}" height="20"/>     <combobox name="box1" height="30" margin="30" itemssource="{binding items}"/> 

even more examples

<grid>     <grid.rowdefinitions>         <rowdefinition height="auto"/>         <rowdefinition height="*"/>     </grid.rowdefinitions>     <textblock text="{binding elementname=box1, path=selecteditem}" height="20"/>     <listview name="box1" itemssource="{binding items}" grid.row="1">         <listview.view>             <gridview>                 <gridviewcolumn header="name" width="120" displaymemberbinding="{binding}"/>             </gridview>         </listview.view>     </listview> </grid> 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -