WPF DataGrid中列的屬性繫結問題
WPF中的DataGrid中Column的IsReadOnly和VIsibility等屬性繫結時,總沒有任何效果,輸出裡也顯示找不到,搜了半天才發現,原來Column不屬於visual 或 logical tree,所以不能在樹上搜索他的繫結源,需要藉助其他方法給屬性指定資料來源,方法如下:
<UserControl.Resources> <local:BindingProxy x:Key="proxy" Data="{Binding}" /> </UserControl.Resources> <DataGridTemplateColumn Visibility="{Binding Data.IsVisible, Source={StaticResource proxy}, Converter={StaticResource BooleanToVisibilityConverter}}">
public class BindingProxy : Freezable { protected override Freezable CreateInstanceCore() { return new BindingProxy(); } public object Data { get { return (object)GetValue(DataProperty); } set { SetValue(DataProperty, value); } } // Using a DependencyProperty as the backing store for Data. // This enables animation, styling, binding, etc... public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null)); }
原文地址:https://stackoverflow.com/questions/15494226/cannot-find-source-for-binding-with-reference-relativesource-findancestor
相關推薦
WPF DataGrid中列的屬性繫結問題
WPF中的DataGrid中Column的IsReadOnly和VIsibility等屬性繫結時,總沒有任何效果,輸出裡也顯示找不到,搜了半天才發現,原來Column不屬於visual 或 logical tree,所以不能在樹上搜索他的繫結源,需要藉助其他方法給屬性指定資
DataGrid中ContextMenu的繫結
在WPF中使用DataGrid,有時會用到ContextMenu,當ContextMenu需要繫結DataGrid列的時候,我們按平時的繫結就直接用ElementName的方式了,但在ContextMenu中是不可 以的,可以用以下方式進行繫結: <MenuIt
qml中的屬性繫結與賦值
淺談qml屬性繫結與賦值 屬性賦值 就字面意思,賦一個值給屬性 Rectangle { id:rect Component.onCompeleted:{ rect.width = 10; // 賦值 re
wpf datagrid中的 DataGridComboBoxColumn資料繫結
wpf 中datagridcomboxColumn的資料繫結主要分下面幾步 1。提供資料來源型別:可以是任意的資料型別:這裡用列舉 public enum OrderStatus { None, New, Processing, Shipped, Received
WPF:後臺獲取DataGrid列的繫結欄位。
前臺: <DataGrid Name="dg" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn B
C# wpf 中的資料繫結4-2(15)
同一個資料來源繫結到兩個或多個控制元件上。如我們的示例中把ListBox的選中項繫結到TextBox與TextBlock。 在繫結語法中增加一個 Mode 屬性,即繫結模式。對於我們的示例,我們把TextBlock的繫結語法中的Mode屬性設為 OneWay 。把TextB
C# WPF在xaml中的資料繫結
在WPF的繫結中個人分為兩種:非集合資料繫結和集合資料繫結。 非集合資料繫結:指的是包含資料為單個de控制元件的資料繫結,而不是有很多子項,例如Button,TextBox,TextBlock等等的繫結。 集合資料繫結:指的是包含很多子項的控制元件的資料繫結,例如ListV
Vue-中若元素屬性繫結的值需要為數字時坑
Vue-中若元素屬性需要繫結的值為數字時的處理 1.如果直接這樣寫: <select v-model='value'> <option value='數字'>...</option> </select> 這時vue並不會
Vue中img的src屬性繫結
<img src="./img/red.png'" /> // 頁面顯示圖片 如果遇到圖片是動態的,也就是說在不同情況下顯示不同的圖片,也就是下面使用的屬性繫結 <img :src="imgPath" /> // imgPath
Vue中img的src屬性繫結與static資料夾
不少人在vue的開發中遇到這樣一個問題: img的src屬性繫結url變數,然而圖片載入失敗。 大部分的情況中,是開發者使用了錯誤的寫法,例如: <img src="{{ imgUrl }}"/> 這樣寫肯定是不對的,正確的寫法應該使用v-
WPF中關於資料繫結的三種方式及注意細節
前言》 首先,簡單介紹一下,什麼是資料繫結?一種用宣告的方式將控制元件和資料繫結在一起的方式。 簡單來理解一下就是:控制元件的屬性由你繫結的資料來動態判斷的方式。 《核心前提部分》 一個繫結(Binding)關係由四個元件構成: 1
DataGridView列中加CheckBox繫結資料庫
程式功能: 1.在DataGridView中新增CheckBox列,然後使用DataGridView來繫結Oracle資料 2.繫結的資料在DataGridView顯示時選擇需要顯示的資料,然後勾選CheckBox來刪除資料庫中的資料 private System.Wind
WPF屬性繫結測試(索引器方式)
小結: 如果屬性繫結路徑上的任何可通知變化屬性發生改變,其路徑及以下路徑都視為發生了變化,不管是否是可通知變化屬性,都會重新繫結新值。看來微軟對於繫結的機制是下了功夫的,如果採用簡單的反射,路徑尋找的方式,如果頁面元素比較多,層次比較多,效率肯定有問題的,看來有時間得反
WPF 元素tag屬性繫結一個屬性或一個物件
<Window x:Class="CollectionBinding.CategoryDataTemp" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xm
【Vue】vue中img的src屬性繫結問題
問題:img的src屬性填寫的圖片地址,可以正常渲染,但是一旦利用繫結:src屬性的時候,圖片就載入失敗了 需求:滑鼠移入切換圖片 上一位前端小哥哥,沒做這個互動,我接手後加上去,很簡答的互動,我替換圖片的時候準備三元判斷,src需要屬性繫結,於是發現同樣的地
總結:WPF中模板需要繫結父級別的ViewModel該如何處理
<ListBox ItemsSource="{Binding ClassCollection}"> <ListBox.ItemContainerStyle>
在wpf datagrid中,想要根據一個條件來改變datagrid行的背景顏色
修改 ++ ini orb 方法名 rgb .cn html over 原文:在wpf datagrid中,想要根據一個條件來改變datagrid行的背景顏色 在wpf
WPF日積月累之TreeView動態繫結
一、概述 本文演示瞭如何遞迴生成資料,用於繫結TreeView以及TreeItem的雙擊事件。 二、參考程式碼 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentMod
v-bind 屬性繫結
1.v-bind:title="title" 繫結誰和誰繫結。 2.v-bind:title="title" 簡寫::title="title" <!DOCTYPE html> <html> <head> <meta name="viewport"
vue中父子元件繫結事件
父子元件繫結事件: 注意:父元件是自定義事件,由子元件傳遞觸發事件資訊;子元件是系統事件比如:click等 <div id="app"> <counter @handle="fatherEvent"></counter>