Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Snoopwpf
提交
74a0e14d
S
Snoopwpf
项目概览
jobily
/
Snoopwpf
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Snoopwpf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
74a0e14d
编写于
9月 18, 2022
作者:
B
Bastian Schmidt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
First steps for showing the source of value inheritance
上级
b30c027a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
11 deletion
+35
-11
Snoop.Core/Commands/InheritedValueSourceHelper.cs
Snoop.Core/Commands/InheritedValueSourceHelper.cs
+10
-4
Snoop.Core/Controls/PropertyGrid2.xaml
Snoop.Core/Controls/PropertyGrid2.xaml
+15
-7
Snoop.Core/Infrastructure/UIObjectNameHelper.cs
Snoop.Core/Infrastructure/UIObjectNameHelper.cs
+10
-0
未找到文件。
Snoop.Core/Commands/InheritedValueSourceHelper.cs
浏览文件 @
74a0e14d
...
@@ -10,12 +10,13 @@
...
@@ -10,12 +10,13 @@
using
System.Windows
;
using
System.Windows
;
using
System.Windows.Media
;
using
System.Windows.Media
;
using
Snoop.Infrastructure
;
using
Snoop.Infrastructure
;
using
Snoop.Infrastructure.Helpers
;
public
class
InheritedValueSourceHelper
:
INotifyPropertyChanged
public
class
InheritedValueSourceHelper
:
INotifyPropertyChanged
{
{
public
static
readonly
InheritedValueSourceHelper
Instance
=
new
();
public
static
readonly
InheritedValueSourceHelper
Instance
=
new
();
private
static
readonly
PropertyInfo
?
inheritanceParentPropertyInfo
=
typeof
(
DependencyObject
).
GetProperty
(
"InheritanceParent"
,
BindingFlags
.
Instance
|
BindingFlags
.
Public
|
BindingFlags
.
NonPublic
);
//
private static readonly PropertyInfo? inheritanceParentPropertyInfo = typeof(DependencyObject).GetProperty("InheritanceParent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
public
event
PropertyChangedEventHandler
?
PropertyChanged
;
public
event
PropertyChangedEventHandler
?
PropertyChanged
;
...
@@ -40,19 +41,21 @@ private void CommandExecute(object? obj)
...
@@ -40,19 +41,21 @@ private void CommandExecute(object? obj)
var
sources
=
GetInheritedValueSources
(
currentTarget
,
property
);
var
sources
=
GetInheritedValueSources
(
currentTarget
,
property
);
MessageBox
.
Show
(
string
.
Join
(
Environment
.
NewLine
,
sources
.
Select
(
x
=>
$"
{
UIObjectNameHelper
.
GetName
(
x
)}
"
)));
MessageBox
.
Show
(
string
.
Join
(
Environment
.
NewLine
,
sources
.
Select
(
x
=>
$"
{
UIObjectNameHelper
.
GetName
AndType
(
x
)}
"
)));
}
}
private
static
ObservableCollection
<
DependencyObject
>
GetInheritedValueSources
(
DependencyObject
?
currentTarge
t
,
DependencyProperty
property
)
private
static
ObservableCollection
<
DependencyObject
>
GetInheritedValueSources
(
DependencyObject
?
toInspec
t
,
DependencyProperty
property
)
{
{
var
sources
=
new
ObservableCollection
<
DependencyObject
>();
var
sources
=
new
ObservableCollection
<
DependencyObject
>();
var
currentTarget
=
toInspect
;
if
(
currentTarget
is
not
null
)
if
(
currentTarget
is
not
null
)
{
{
sources
.
Add
(
currentTarget
);
sources
.
Add
(
currentTarget
);
}
}
while
((
currentTarget
=
inheritanceParentPropertyInfo
?.
GetValue
(
currentTarget
)
as
DependencyObject
)
is
not
null
)
//while ((currentTarget = inheritanceParentPropertyInfo?.GetValue(currentTarget) as DependencyObject) is not null)
while
(
currentTarget
is
not
null
)
{
{
sources
.
Add
(
currentTarget
);
sources
.
Add
(
currentTarget
);
...
@@ -60,6 +63,9 @@ private static ObservableCollection<DependencyObject> GetInheritedValueSources(D
...
@@ -60,6 +63,9 @@ private static ObservableCollection<DependencyObject> GetInheritedValueSources(D
{
{
break
;
break
;
}
}
currentTarget
=
LogicalTreeHelper
.
GetParent
(
currentTarget
)
??
VisualTreeHelper
.
GetParent
(
currentTarget
);
}
}
return
sources
;
return
sources
;
...
...
Snoop.Core/Controls/PropertyGrid2.xaml
浏览文件 @
74a0e14d
<!--
<!--
(c) Copyright Cory Plotts.
(c) Copyright Cory Plotts.
This source is subject to the Microsoft Public License (Ms-PL).
This source is subject to the Microsoft Public License (Ms-PL).
Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
<controls:Inspector x:Class="Snoop.Controls.PropertyGrid2"
<controls:Inspector x:Class="Snoop.Controls.PropertyGrid2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:commands="clr-namespace:Snoop.Core.Commands"
xmlns:controls="clr-namespace:Snoop.Controls"
xmlns:controls="clr-namespace:Snoop.Controls"
xmlns:converters="clr-namespace:Snoop.Converters"
xmlns:converters="clr-namespace:Snoop.Converters"
xmlns:infrastructure="clr-namespace:Snoop.Infrastructure"
xmlns:infrastructure="clr-namespace:Snoop.Infrastructure"
...
@@ -100,12 +101,19 @@
...
@@ -100,12 +101,19 @@
<DataTemplate x:Key="ValueSourceTemplate"
<DataTemplate x:Key="ValueSourceTemplate"
DataType="infrastructure:PropertyInformation">
DataType="infrastructure:PropertyInformation">
<TextBlock Height="16"
<StackPanel Orientation="Horizontal">
Text="{Binding ValueSourceBaseValueSource}">
<TextBlock Text="{Binding ValueSourceBaseValueSource}">
<TextBlock.ToolTip>
<TextBlock.ToolTip>
<TextBlock Text="{Binding ValueSourceBaseValueSource}" />
<TextBlock Text="{Binding ValueSourceBaseValueSource}" />
</TextBlock.ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</TextBlock>
<Button Margin="2 0 0 0"
Command="{Binding Path=Command, Source={x:Static commands:InheritedValueSourceHelper.Instance}}"
CommandParameter="{Binding}"
Content="O"
Visibility="{Binding ValueSourceBaseValueSource, Converter={x:Static converters:EqualsToVisibilityConverter.DefaultInstance}, ConverterParameter=Inherited}" />
</StackPanel>
</DataTemplate>
</DataTemplate>
</ResourceDictionary>
</ResourceDictionary>
</Grid.Resources>
</Grid.Resources>
...
...
Snoop.Core/Infrastructure/UIObjectNameHelper.cs
浏览文件 @
74a0e14d
...
@@ -5,6 +5,16 @@
...
@@ -5,6 +5,16 @@
public
static
class
UIObjectNameHelper
public
static
class
UIObjectNameHelper
{
{
public
static
string
GetNameAndType
(
DependencyObject
?
dependencyObject
)
{
if
(
dependencyObject
is
null
)
{
return
string
.
Empty
;
}
return
$"
{
GetName
(
dependencyObject
)}
(
{
dependencyObject
.
GetType
().
Name
}
)"
;
}
public
static
string
GetName
(
DependencyObject
?
dependencyObject
)
public
static
string
GetName
(
DependencyObject
?
dependencyObject
)
{
{
var
result
=
string
.
Empty
;
var
result
=
string
.
Empty
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录