WPF常用技巧匯總 - Part 2

WPF常用技巧匯總-CSDN博客

主要用于記錄工作中發現的一些問題和常見的解決方法。

目錄

WPF常用技巧匯總-CSDN博客

1. DataGrid Tooltip - Multiple

2. DataGrid Tooltip - Cell值和ToolTip值一樣

3. DataGrid Tooltip - Cell值和ToolTip值不一樣

4. DataGrid - Ctrl +A /Ctrl + C復制的內容不是Cell的值

5. DataGrid - Edit -Combox

6. DataGrid - 解決DataGridTemplateColumn無法排序的問題


1. DataGrid Tooltip - Multiple

 <DataGridTemplateColumn MinWidth="120" x:Name="colExclude"><DataGridTemplateColumn.HeaderTemplate><DataTemplate><Grid><Grid.RowDefinitions><RowDefinition Height="*"/><RowDefinition Height="*"/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="*"></ColumnDefinition><ColumnDefinition Width="*"></ColumnDefinition><ColumnDefinition Width="*"></ColumnDefinition></Grid.ColumnDefinitions><Label Style="{StaticResource LabelHeaderWhiteColorStyle}" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" Content="Exclude"/><Border Grid.Row="0" Grid.Column="2" Width="22" Margin="0,2" ToolTipService.ShowDuration="50000"><Border.Background><ImageBrush ImageSource="..\..\..\Images\question_mark.png"/></Border.Background><Border.ToolTip><ToolTip><StackPanel><Label Content="Tool Tip:" HorizontalAlignment="Center"/><Label Content="Notice = Exclude Notice: Lender selected will not be available in the Notice Preview"/><Label Content="JobTicket = Exclude Job Ticket: Lender selected will not be available in the Job Ticket Preview"/><Label Content="Recon = Exclude Distribution: Lender selected will decrease the Total Cash Actual expected in Reconciliation"/></StackPanel></ToolTip></Border.ToolTip></Border><Label Style="{StaticResource LabelHeaderWhiteColorStyle}" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" Content="Notice"/><Label Style="{StaticResource LabelHeaderWhiteColorStyle}" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Content="JobTicket"/><Label Style="{StaticResource LabelHeaderWhiteColorStyle}" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left" Content="Recon"/></Grid></DataTemplate></DataGridTemplateColumn.HeaderTemplate><DataGridTemplateColumn.CellTemplate><DataTemplate><Grid IsEnabled="{Binding DataContext.IsCashDistributeEnable, RelativeSource={RelativeSource AncestorType={x:Type bs:AgencyWindowBase}},Mode=OneWay}"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="*"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><CheckBox Style="{StaticResource CheckBoxInCellStyle}" HorizontalAlignment="Left" Grid.Column="0" IsChecked="{Binding DataContext.ExcludeFromNotice, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}},Mode=TwoWay}" IsThreeState="False" IsEnabled="{Binding DataContext.IsExcludeNoticeEnabled, RelativeSource={RelativeSource AncestorType={x:Type bs:AgencyWindowBase}},Mode=OneWay}"/><CheckBox Style="{StaticResource CheckBoxInCellStyle}" Grid.Column="1" IsChecked="{Binding DataContext.ExcludeFromJobTicket, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}},Mode=TwoWay}" IsThreeState="False" IsEnabled="{Binding DataContext.IsExcludeJTAndReconEnable, RelativeSource={RelativeSource AncestorType={x:Type bs:AgencyWindowBase}},Mode=OneWay}" HorizontalAlignment="Center"/><CheckBox Style="{StaticResource CheckBoxInCellStyle}" HorizontalAlignment="Right" Grid.Column="2" IsChecked="{Binding DataContext.ExcludeFromRecon, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}},Mode=TwoWay}" IsThreeState="False" IsEnabled="{Binding DataContext.IsExcludeJTAndReconEnable, RelativeSource={RelativeSource AncestorType={x:Type bs:AgencyWindowBase}},Mode=OneWay}"/></Grid></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>

2. DataGrid Tooltip - Cell值和ToolTip值一樣

<DataGridTextColumn Header="Borrower Name" Binding="{Binding BorrowerName}" IsReadOnly="True" MinWidth="150" Width="150" MaxWidth="1000"><DataGridTextColumn.CellStyle><Style TargetType="DataGridCell"><Setter Property="ToolTip" Value="{Binding BorrowerName}"></Setter></Style></DataGridTextColumn.CellStyle>
</DataGridTextColumn>

3. DataGrid Tooltip - Cell值和ToolTip值不一樣

<DataGridTextColumn Header="Borrower Name" Binding="{Binding BorrowerName}" IsReadOnly="True" MinWidth="150" Width="150" MaxWidth="1000"><DataGridTextColumn.CellStyle><Style TargetType="DataGridCell"><Setter Property="ToolTip" Value="{Binding BorrowerNameToolTip}"></Setter></Style></DataGridTextColumn.CellStyle>
</DataGridTextColumn>

4. DataGrid - Ctrl +A /Ctrl + C復制的內容不是Cell的值

默認copy的內容是Cell的value, 即Binding的field的value。

但是有時候我們想copy的是其他的field值,怎么辦??

比如我們這個列顯示的是一些內容的縮寫,但是拷貝的時候需要拷貝全整的內容。

此時可以通過指定ClipboardContentBinding去解決此類問題。

 <DataGridTextColumn Header="Sending To" Binding="{Binding singleRecipient}" IsReadOnly="True" MinWidth="200" Width="240" ClipboardContentBinding="{Binding Recipients}"><DataGridTextColumn.CellStyle><Style TargetType="DataGridCell"><Setter Property="ToolTip" Value="{Binding Recipients}"></Setter></Style></DataGridTextColumn.CellStyle></DataGridTextColumn>

5. DataGrid - Edit -Combox

 <DataGridTemplateColumn Width="180" IsReadOnly="False"><DataGridTemplateColumn.HeaderTemplate><DataTemplate><StackPanel Orientation="Horizontal"><TextBlock FontWeight="SemiBold" Text="Account Name "/><Image Source="..\..\..\Images\question_mark.png" Height="15" Width="15" HorizontalAlignment="Right" Grid.Column="1" ToolTipService.ToolTip="Bla bla bla..." /></StackPanel></DataTemplate></DataGridTemplateColumn.HeaderTemplate><DataGridTemplateColumn.CellTemplate><DataTemplate><StackPanel Orientation="Horizontal" HorizontalAlignment="Left"><Label ToolTip="{Binding  SelectedAccount.Name}" Content="{Binding SelectedAccount.Name}" Visibility="{Binding Path=IsAccountEdit, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=false}"></Label></StackPanel></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.CellEditingTemplate><DataTemplate><ComboBox Visibility="{Binding Path=IsAccountEditShow, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=false}" Width="170" SelectedValue="{Binding SelectedAccount, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, Mode=FindAncestor}}" x:Name="cbxSelectedAcount" SelectionChanged="cbxSelectedAcount_SelectionChanged"ItemsSource="{Binding Path=Accounts, UpdateSourceTrigger=PropertyChanged}"IsEnabled="{Binding DataContext.NoticeTemplate.Payment.IsTypeBorrowingOIDAndHasAgentAccountId, Converter={StaticResource InverseBooleanConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, Mode=FindAncestor}}"><ComboBox.ItemTemplate><DataTemplate><TextBlock Text="{Binding Account.Name}" Foreground="Black"/></DataTemplate></ComboBox.ItemTemplate></ComboBox></DataTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>
      private void cbxSelectedAcount_SelectionChanged(object sender, SelectionChangedEventArgs e){if (e.AddedItems.Count > 0){var selectedAccount = e.AddedItems[0] as AccountDto;}}

6. DataGrid - 解決DataGridTemplateColumn無法排序的問題

DataGrid設置了CanUserSortColumns="True"后,DataGridTemplateColumn點擊Header后無法支持排序。此時可通過指定CanUserSort="True" 和SortMemberPath="SelectedAccount.Name"解決。

      <DataGridTemplateColumn Width="180" IsReadOnly="False" CanUserSort="True" SortMemberPath="SelectedAccount.Name" ><DataGridTemplateColumn.HeaderTemplate><DataTemplate><StackPanel Orientation="Horizontal"><TextBlock FontWeight="SemiBold" Text="Account Name "/><Image Source="..\..\..\Images\question_mark.png" Height="15" Width="15" HorizontalAlignment="Right" Grid.Column="1" ToolTipService.ToolTip="Wire Instructions of the selected Account will be used on the Notice.&#x0a;&#x0a;Accounts are setup at the Facility Level under the Lender's Admin Details.&#x0a;&#x0a;If an Account is unavailable:&#x0a;1) Check if its Currency matches the Payment Currency&#x0a;2) Check it's selected for ALL applicable Payment Types" /></StackPanel></DataTemplate></DataGridTemplateColumn.HeaderTemplate><DataGridTemplateColumn.CellTemplate><DataTemplate><StackPanel Orientation="Horizontal" HorizontalAlignment="Left"><Label ToolTip="{Binding  SelectedAccount.Name}" Content="{Binding SelectedAccount.Name}" Visibility="{Binding Path=IsAccountEdit, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=false}"></Label></StackPanel></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.CellEditingTemplate><DataTemplate><ComboBox Visibility="{Binding Path=IsAccountEditShow, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=false}"  Width="170" SelectedValue="{Binding SelectedAccount, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}, Mode=FindAncestor}}" x:Name="cbxSelectedAcountForLender" SelectionChanged="cbxSelectedAcountForLender_SelectionChanged"ItemsSource="{Binding Path=Accounts, UpdateSourceTrigger=PropertyChanged}"><ComboBox.ItemTemplate><DataTemplate><TextBlock Text="{Binding Account.Name}" Width="150" Foreground="Black"/></DataTemplate></ComboBox.ItemTemplate></ComboBox></DataTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/903457.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/903457.shtml
英文地址,請注明出處:http://en.pswp.cn/news/903457.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

uniapp打包apk如何實現版本更新

我們做的比較簡單&#xff0c;在后端設置版本號&#xff0c;并在uniapp的config.js中定義版本號&#xff0c;每次跟后端的進行對比&#xff0c;不一致的話就更新。 一、下載apk 主要代碼&#xff08;下載安裝包&#xff0c;并進行安裝&#xff0c;一般得手動同意安裝&#xf…

局部和整體的關系

Prompt&#xff1a;為什么要研究局部和整體的關系呢&#xff1f;是因為很多情況下&#xff0c;局部就能表達出整體&#xff1f; 這是一個非常本質的問題&#xff0c;其實你已經接近數學和物理中“幾何本質”的核心了。我們研究局部和整體的關系&#xff0c;是因為&#xff1a;…

企業辦公協同平臺安全一體化生態入住技術架構與接口標準分析報告

全球組織數字化與智能化背景下 企業辦公協同平臺安全一體化生態入住技術架構與接口標準分析報告 一、背景與市場需求 市場規模與增量 根據Statista數據&#xff0c;全球協同辦公平臺市場規模預計從2023年的$480億增長至2027年的$900億&#xff0c;年復合增長率&#xff08;CAG…

【2025最新面試八股常問知識點】HTTP1.0,HTTP1.1,HTTP2.0,HTTP3.0,HTTP的進化之路。

HTTP 超文本傳輸協議&#xff08;英文&#xff1a;HyperText Transfer Protocol&#xff0c;縮寫&#xff1a;HTTP&#xff09;是一種用于分布式、協作式和超媒體信息系統的應用層協議。設計HTTP最初的目的是為了提供一種發布和接收HTML頁面的方法。通過HTTP或者HTTPS協議請求的…

【算法練習】歸并排序和歸并分治

文章目錄 1.歸并排序1.1 遞歸版本1.2 非遞歸版本 2.歸并分治2.1 計算數組的小和2.2 計算翻轉對 1.歸并排序 歸并排序的核心步驟是&#xff1a; 拆分&#xff1a;將無序數組不斷對半拆分成小塊&#xff0c;直到每個小塊只剩一個元素&#xff08;自然有序&#xff09;。 合并&a…

域對齊是什么

域對齊&#xff08;Domain Alignment&#xff09;是在機器學習和計算機視覺等領域中常用的技術 定義 域對齊旨在將不同域&#xff08;Domain&#xff09;的數據映射到一個共同的特征空間中&#xff0c;使得來自不同域的數據在該空間中具有相似的分布。這里的“域”可以指代不…

【linux】git安裝、升級

git安裝、升級 一、快捷安裝版本2.18.0二、自定義版本安裝&#xff08;安裝、升級&#xff09;1、移除舊文件2、安裝所需依賴3、選擇指定版本4、解壓文件、編譯5、增加環境變量&#xff0c;驗證是否版本 三、升級 一、快捷安裝版本2.18.0 yum install git git --version二、自…

編程日志4.24

棧的鏈表基礎表示結構 #include<iostream> #include<stdexcept> using namespace std; //模板聲明&#xff0c;表明Stack類是一個通用的模板&#xff0c;可以用于存儲任何類型的元素T template<typename T> //棧的聲明 //Stack類的聲明&#xff0c;表示一…

《冰雪傳奇點卡版》:探索冰雪世界的傳奇旅程!

《冰雪傳奇點卡版》以“純凈打金”為核心&#xff0c;摒棄復雜付費坑&#xff0c;回歸經典傳奇玩法。以下從核心玩法、資源獲取、職業搭配、交易變現四維度展開&#xff0c;助你高效開啟冰雪傳奇之旅。 一、核玩法解析&#xff1a;如何高效獲取資源&#xff1f; 1. 職業定位與…

DeepClaude開源程序可以實現代碼生成、創作詩句以及內容創作等功能

一、軟件介紹 文末提供程序和源碼下載 DeepClaude開源程序是增強的 AI&#xff0c;可以實現代碼生成&#xff1a;DeepSeek r1 Claude 3.7 十四行詩 - 無與倫比的性能&#xff01;內容創作&#xff1a;DeepSeek r1 Gemini 2.5 Pro - 卓越的質量&#xff01;OpenAI 兼容。流媒…

Java常用注解通俗解釋

注解就像是給Java代碼貼的"便利貼"&#xff0c;它們不會改變代碼本身的邏輯&#xff0c;但能給編譯器、開發工具或運行時環境提供額外信息。下面我用最通俗的方式解釋Java中最常用的注解&#xff1a; 一、基礎篇&#xff1a;人人必知的注解 1. Override - "我…

vscode chrome調試怎么在所有瀏覽器都好使

chrome調試時只能在打開的瀏覽器里進行調試&#xff0c;其它打開的chrome瀏覽器就不能調試了&#xff0c;怎么解決。 右鍵點擊 Chrome 的快捷方式圖標&#xff0c;選擇屬性 在目標一欄&#xff0c;最后加上--remote-debugging-port9222 注意要用空格隔開 lanch.json 文件配置 …

Unity PBR基礎知識

PBR原理 基于物理的渲染&#xff08;Physically Based Rendering&#xff0c;PBR&#xff09;是指使用基于物理原理和微平面理論建模的著色/光照模型&#xff0c;以及使用從現實中測量的表面參數來準確表示真實世界材質的渲染理念。 PBR基礎理念 微平面理論&#xff08;Micr…

COM組件使用方法

普通COM組件&#xff08;如DLL&#xff09;僅暴露方法/屬性接口&#xff0c;而ActiveX控件&#xff08;如OCX&#xff09;需要可視化交互&#xff08;如按鈕、表格&#xff09;&#xff0c;需通過 ??AxInterop?? 包裝器實現宿主環境集成。 項目中引入ActiveX控件流程如下。…

在 Spring Boot 項目中如何使用索引來優化 SQL 查詢?

在 Spring Boot 項目中使用索引來優化 SQL 查詢是提升數據庫性能最常用的方法之一。下面是詳細的步驟和實踐指南&#xff1a; 核心目標&#xff1a;讓數據庫能夠通過掃描索引&#xff08;小范圍、有序的數據結構&#xff09;快速定位到所需數據行&#xff0c;而不是掃描整個表…

Vue3生產環境與Vue Devtools

在 Vue 3 的生產環境中&#xff0c;默認情況下 Vue Devtools 是無法正常使用 的&#xff0c;但開發者可以通過配置強制啟用。以下是關鍵信息總結&#xff1a; &#x1f4cc; 核心結論 默認不可用 Vue 3 生產構建會移除 Devtools 支持以優化性能和安全性。 可強制啟用 通過構建…

ARP滲透學習1

ARP協議工作原理 1. 什么是ARP ARP定義: 地址解析協議&#xff08;Address Resolution Protocol&#xff09;&#xff0c;是根據IP地址獲取物理地址的一個TCP/IP協議。 2. 工作原理 ARP表: 每臺計算機都需要一個ARP表&#xff0c;用來保存IP地址和MAC地址的映射關系。查詢過…

甲骨文云2025深度解析:AI驅動的云原生生態與全球化突圍

一、戰略轉型&#xff1a;從數據庫巨頭到AI云服務先鋒 1. 技術重心向AI與云深度遷移 甲骨文在2025年加速向AI原生云架構轉型&#xff0c;其核心戰略圍繞生成式AI與量子計算展開。通過推出Oracle 23ai自治數據庫&#xff0c;深度集成AI向量搜索功能&#xff0c;并重構云基礎設…

【網絡原理】TCP異常處理(二):連接異常

目錄 一. 由進程崩潰引起的連接斷開 二. 由關機引起的連接斷開 三. 由斷電引起的連接斷開 四. 由網線斷開引起的連接斷開 一. 由進程崩潰引起的連接斷開 在一般情況下&#xff0c;進程無論是正常結束&#xff0c;還是異常崩潰&#xff0c;都會觸發回收文件資源&#xff0c;…

想做博聞強記的自己

2025年4月29日&#xff0c;13~25℃&#xff0c;還好 待辦&#xff1a; 冶金《物理》期末測試 閱卷&#xff08;冶金《物理》期末測試試卷&#xff09; 重修《物理》《物理2》電子材料歸檔 規則變更&#xff0c;《高等數學2》期末試卷推倒重來 遇見&#xff1a;直播畫面。 感受…