Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lindexi_gd
Uno
提交
3ea1c981
U
Uno
项目概览
lindexi_gd
/
Uno
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
Uno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3ea1c981
编写于
6月 18, 2023
作者:
A
Andres Pineda
提交者:
GitHub
6月 18, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12487 from ajpinedam/ajpm/fix.commandbar.appbaricon
fix(droid): CommandBar AppBarIcon binding issues
上级
42df67b3
9580db2c
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
215 addition
and
18 deletion
+215
-18
src/SamplesApp/UITests.Shared/Assets/closeIcon.png
src/SamplesApp/UITests.Shared/Assets/closeIcon.png
+0
-0
src/SamplesApp/UITests.Shared/Assets/filter.png
src/SamplesApp/UITests.Shared/Assets/filter.png
+0
-0
src/SamplesApp/UITests.Shared/UITests.Shared.projitems
src/SamplesApp/UITests.Shared/UITests.Shared.projitems
+11
-2
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/CommandBar/CommandBarViewModel.cs
...indows_UI_Xaml_Controls/CommandBar/CommandBarViewModel.cs
+14
-0
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml
...mmandBar/CommandBar_Native_With_AppBarButton_Binding.xaml
+47
-0
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs
...ndBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs
+78
-0
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/FramePages/Page_With_AppBarButton_Visibility_Bound.xaml
...s/FramePages/Page_With_AppBarButton_Visibility_Bound.xaml
+12
-1
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AppBarButton.cs
...ests/Tests/Windows_UI_Xaml_Controls/Given_AppBarButton.cs
+30
-0
src/Uno.UI/Controls/CommandBar/AppBarButtonRenderer.Android.cs
...no.UI/Controls/CommandBar/AppBarButtonRenderer.Android.cs
+1
-3
src/Uno.UI/DrawableHelper.Android.cs
src/Uno.UI/DrawableHelper.Android.cs
+3
-2
src/Uno.UI/UI/Xaml/Media/ImageSource.Android.cs
src/Uno.UI/UI/Xaml/Media/ImageSource.Android.cs
+1
-1
src/Uno.UWP/Helpers/DrawableHelper.Android.cs
src/Uno.UWP/Helpers/DrawableHelper.Android.cs
+18
-9
未找到文件。
src/SamplesApp/UITests.Shared/Assets/closeIcon.png
0 → 100644
浏览文件 @
3ea1c981
382 字节
src/SamplesApp/UITests.Shared/Assets/filter.png
0 → 100644
浏览文件 @
3ea1c981
219 字节
src/SamplesApp/UITests.Shared/UITests.Shared.projitems
浏览文件 @
3ea1c981
...
...
@@ -1266,6 +1266,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\CommandBar_Native_With_AppBarButton_Binding.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\IconSourceTests\IconSourceElementTests.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
...
...
@@ -2905,7 +2909,7 @@
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ContentControlTestsControl\ContentControl_ComboBoxSetNull.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ContentControlTestsControl\ContentControl_FindName.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
...
...
@@ -5693,6 +5697,9 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BorderTests\BorderWithNullBrushAndNonZeroThickness.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BorderTests\PanelWithNullBrushAndNonZeroThickness.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\CommandBar_Native_With_AppBarButton_Binding.xaml.cs">
<DependentUpon>CommandBar_Native_With_AppBarButton_Binding.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\ImageSourceWriteableBitmapInvalidate_Stretch.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\IconSourceTests\IconSourceElementTests.xaml.cs">
<DependentUpon>IconSourceElementTests.xaml</DependentUpon>
...
...
@@ -8923,6 +8930,7 @@
<Content Include="$(MSBuildThisFileDirectory)Assets\cart.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\check.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\CheckBox.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\closeIcon.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\colored-ellipse.jpg" />
<Content Include="$(MSBuildThisFileDirectory)Assets\ColorPicker.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\colors300.png" />
...
...
@@ -8934,6 +8942,7 @@
<Content Include="$(MSBuildThisFileDirectory)Assets\Diagnostics\exclamation.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Diagnostics\movie_type_dbox.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\DropdownButton.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\filter.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\FlipView.png" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\Even Badder Mofo.ttf" />
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\FamilyGuy-4grW.ttf" />
...
...
@@ -9088,4 +9097,4 @@
<Content Include="$(MSBuildThisFileDirectory)Assets\libre-camera-panorama.svg" />
</ItemGroup>
<Import Project="ItemExclusions.props" />
</Project>
</Project>
\ No newline at end of file
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/CommandBar/CommandBarViewModel.cs
浏览文件 @
3ea1c981
...
...
@@ -2,6 +2,7 @@
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Input
;
using
Uno.UI.Samples.UITests.Helpers
;
using
Windows.UI.Core
;
...
...
@@ -12,12 +13,15 @@ namespace Uno.UI.Samples.Presentation.SamplePages
private
string
_dynamicTitle
;
private
string
_dynamicSubTitle1
;
private
string
_dynamicSubTitle2
;
private
bool
_isChecked
;
public
CommandBarViewModel
(
CoreDispatcher
dispatcher
)
:
base
(
dispatcher
)
{
ToggleChecked
=
GetOrCreateCommand
(()
=>
IsChecked
=
!
IsChecked
);
StartData
();
}
public
ICommand
ToggleChecked
{
get
;
}
private
async
void
StartData
()
{
...
...
@@ -59,5 +63,15 @@ namespace Uno.UI.Samples.Presentation.SamplePages
_dynamicSubTitle2
=
value
;
RaisePropertyChanged
();
}
}
public
bool
IsChecked
{
get
{
return
_isChecked
;
}
set
{
_isChecked
=
value
;
RaisePropertyChanged
();
}
}
}
}
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml
0 → 100644
浏览文件 @
3ea1c981
<Page
x:Class="UITests.Windows_UI_Xaml_Controls.CommandBar.CommandBar_Native_With_AppBarButton_Binding"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.CommandBar"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xamarin="http://nventive.com/xamarin"
xmlns:ios="http://nventive.com/ios"
xmlns:android="http://nventive.com/android"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d xamarin ios android"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<Style x:Name="NativeCommandbarStyle"
TargetType="CommandBar"
xamarin:BasedOn="{StaticResource NativeDefaultCommandBar}">
<Setter Property="Background"
Value="Blue" />
<Setter Property="Foreground"
Value="White" />
</Style>
<local:FromNullableBoolToCustomValueConverter x:Key="IsCheckedToIcon"
TrueValue="ms-appx:///Assets/closeIcon.png"
NullOrFalseValue="ms-appx:///Assets/filter.png" />
</Page.Resources>
<StackPanel Background="White">
<xamarin:Grid>
<CommandBar Content="CommandBar with DataContext Set"
Style="{StaticResource NativeCommandbarStyle}"
Grid.Row="0">
<CommandBar.PrimaryCommands>
<AppBarButton Command="{Binding [ToggleChecked]}"
Label="Order"
Foreground="White">
<AppBarButton.Icon>
<BitmapIcon ShowAsMonochrome="True"
UriSource="{Binding [IsChecked], Converter={StaticResource IsCheckedToIcon}}" />
</AppBarButton.Icon>
</AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
</xamarin:Grid>
</StackPanel>
</Page>
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs
0 → 100644
浏览文件 @
3ea1c981
using
System
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.IO
;
using
System.Linq
;
using
System.Runtime.InteropServices.WindowsRuntime
;
using
Uno.UI.Samples.Controls
;
using
Uno.UI.Samples.Presentation.SamplePages
;
using
Windows.Foundation
;
using
Windows.Foundation.Collections
;
using
Windows.UI.Xaml
;
using
Windows.UI.Xaml.Controls
;
using
Windows.UI.Xaml.Controls.Primitives
;
using
Windows.UI.Xaml.Data
;
using
Windows.UI.Xaml.Input
;
using
Windows.UI.Xaml.Media
;
using
Windows.UI.Xaml.Navigation
;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace
UITests.Windows_UI_Xaml_Controls.CommandBar
{
[
SampleControlInfo
(
"CommandBar"
,
"Native_AppBarButton_Binding"
,
typeof
(
CommandBarViewModel
),
isManualTest
:
true
)]
public
sealed
partial
class
CommandBar_Native_With_AppBarButton_Binding
:
Page
{
public
CommandBar_Native_With_AppBarButton_Binding
()
{
this
.
InitializeComponent
();
}
}
public
class
FromNullableBoolToCustomValueConverter
:
IValueConverter
{
public
object
NullOrFalseValue
{
get
;
set
;
}
public
object
TrueValue
{
get
;
set
;
}
public
object
Convert
(
object
value
,
Type
targetType
,
object
parameter
,
string
language
)
{
if
(
parameter
!=
null
)
{
throw
new
ArgumentException
(
$"This converter does not use any parameters. You should remove \"
{
parameter
}
\" passed as parameter."
);
}
if
(
value
!=
null
&&
!(
value
is
bool
))
{
throw
new
ArgumentException
(
$"Value must either be null or of type bool. Got
{
value
}
(
{
value
.
GetType
().
FullName
}
)"
);
}
if
(
value
==
null
||
!
System
.
Convert
.
ToBoolean
(
value
,
CultureInfo
.
InvariantCulture
))
{
return
NullOrFalseValue
;
}
else
{
return
TrueValue
;
}
}
public
object
ConvertBack
(
object
value
,
Type
targetType
,
object
parameter
,
string
language
)
{
if
(
parameter
!=
null
)
{
throw
new
ArgumentException
(
$"This converter does not use any parameters. You should remove \"
{
parameter
}
\" passed as parameter."
);
}
if
(
object
.
Equals
(
this
.
TrueValue
,
this
.
NullOrFalseValue
))
{
throw
new
InvalidOperationException
(
"Cannot convert back if both custom values are the same"
);
}
return
this
.
TrueValue
!=
null
?
value
.
Equals
(
TrueValue
)
:
!
value
.
Equals
(
this
.
NullOrFalseValue
);
}
}
}
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/FramePages/Page_With_AppBarButton_Visibility_Bound.xaml
浏览文件 @
3ea1c981
...
...
@@ -11,11 +11,22 @@
<Grid>
<CommandBar Content="Page with AppBarButton">
<CommandBar.PrimaryCommands>
<AppBarButton Visibility="{Binding ButtonVisibility, FallbackValue=Collapsed}">
<AppBarButton Visibility="{Binding ButtonVisibility, FallbackValue=Collapsed}"
x:Name="innerBarButton"
x:FieldModifier="public">
<TextBlock x:Name="innerTextBlock"
x:FieldModifier="public"
Text="{Binding ButtonText}" />
</AppBarButton>
<AppBarButton Label="Order"
Foreground="White">
<AppBarButton.Icon>
<BitmapIcon ShowAsMonochrome="True"
x:Name="innerIcon"
x:FieldModifier="public"
UriSource="{Binding CommandBarIcon}" />
</AppBarButton.Icon>
</AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
</Grid>
...
...
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AppBarButton.cs
浏览文件 @
3ea1c981
...
...
@@ -33,17 +33,47 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
page
.
DataContext
=
new
MyContext
();
await
WindowHelper
.
WaitForIdle
();
var
tb
=
page
.
innerTextBlock
;
var
icon
=
page
.
innerIcon
;
Assert
.
IsNotNull
(
tb
);
Assert
.
IsNotNull
(
icon
);
Assert
.
AreEqual
(
"Archaeopteryx"
,
tb
.
Text
);
Assert
.
IsTrue
(
tb
.
ActualWidth
>
0
);
Assert
.
IsTrue
(
tb
.
ActualHeight
>
0
);
}
}
[
TestMethod
]
#if __MACOS__
[
Ignore
(
"Currently fails on macOS, part of #9282 epic"
)]
#endif
public
async
Task
Check_Binding_No_DataContext
()
{
using
(
StyleHelper
.
UseNativeFrameNavigation
())
{
var
frame
=
new
Frame
();
WindowHelper
.
WindowContent
=
frame
;
await
WindowHelper
.
WaitForIdle
();
frame
.
Navigate
(
typeof
(
Page_With_AppBarButton_Visibility_Bound
));
await
WindowHelper
.
WaitForIdle
();
var
page
=
frame
.
Content
as
Page_With_AppBarButton_Visibility_Bound
;
page
.
DataContext
=
null
;
Assert
.
IsNotNull
(
page
);
await
WindowHelper
.
WaitForIdle
();
var
tb
=
page
.
innerTextBlock
;
var
icon
=
page
.
innerIcon
;
var
barButton1
=
page
.
innerBarButton
;
Assert
.
IsNotNull
(
tb
);
Assert
.
IsNotNull
(
icon
);
Assert
.
IsNotNull
(
barButton1
);
Assert
.
AreEqual
(
Visibility
.
Collapsed
,
barButton1
.
Visibility
);
}
}
private
class
MyContext
{
public
Visibility
ButtonVisibility
=>
Visibility
.
Visible
;
public
string
ButtonText
=>
"Archaeopteryx"
;
public
string
CommandBarIcon
=>
"ms-appx:///Assets/linux.png"
;
}
}
}
src/Uno.UI/Controls/CommandBar/AppBarButtonRenderer.Android.cs
浏览文件 @
3ea1c981
#
if
__ANDROID__
using
AndroidX.Core.Graphics.Drawable
;
using
AndroidX.Core.Graphics.Drawable
;
using
Android.Views
;
using
System
;
using
System.Collections.Generic
;
...
...
@@ -208,4 +207,3 @@ namespace Uno.UI.Controls
}
}
}
#endif
src/Uno.UI/DrawableHelper.Android.cs
浏览文件 @
3ea1c981
using
Android.Graphics.Drawables
;
#
nullable
enable
using
Android.Graphics.Drawables
;
using
System
;
using
System.ComponentModel
;
using
Windows.UI.Xaml.Media
;
...
...
@@ -14,7 +15,7 @@ namespace Uno.UI
/// </summary>
/// <param name="uri">URI</param>
/// <returns>Drawable</returns>
public
static
Drawable
FromUri
(
Uri
uri
)
=>
public
static
Drawable
?
FromUri
(
Uri
uri
)
=>
Uno
.
Helpers
.
DrawableHelper
.
FromUri
(
uri
);
}
}
src/Uno.UI/UI/Xaml/Media/ImageSource.Android.cs
浏览文件 @
3ea1c981
...
...
@@ -482,7 +482,7 @@ namespace Windows.UI.Xaml.Media
/// Now available outside in Uno library with <see cref="DrawableHelper"/>.
/// </summary>
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
static
Type
Drawables
public
static
Type
?
Drawables
{
get
=>
Uno
.
Helpers
.
DrawableHelper
.
Drawables
;
set
=>
Uno
.
Helpers
.
DrawableHelper
.
Drawables
=
value
;
...
...
src/Uno.UWP/Helpers/DrawableHelper.Android.cs
浏览文件 @
3ea1c981
#
if
__ANDROID__
#
nullable
enable
using
Android.Graphics.Drawables
;
using
AndroidX.Core.Content
;
using
AndroidX.Core.Graphics.Drawable
;
...
...
@@ -14,12 +14,12 @@ namespace Uno.Helpers
{
public
static
class
DrawableHelper
{
private
static
Dictionary
<
string
,
int
>
_drawablesLookup
;
private
static
Type
_drawables
;
private
static
Dictionary
<
string
,
int
>
?
_drawablesLookup
;
private
static
Type
?
_drawables
;
private
static
Func
<
string
,
int
>
_resolver
;
private
static
Func
<
string
,
int
>
?
_resolver
;
public
static
Type
Drawables
public
static
Type
?
Drawables
{
get
=>
_drawables
;
set
...
...
@@ -84,9 +84,14 @@ namespace Uno.Helpers
/// Finds a Drawable by URI
/// </summary>
/// <param name="uri">Uri</param>
/// <returns>
Drawabl
e</returns>
public
static
Drawable
FromUri
(
Uri
uri
)
/// <returns>
<seealso cref="Drawable"/> for the URI provided or null otherwis
e</returns>
public
static
Drawable
?
FromUri
(
Uri
uri
)
{
if
(
uri
?.
PathAndQuery
is
null
)
{
return
null
;
}
var
id
=
FindResourceIdFromPath
(
uri
.
PathAndQuery
.
TrimStart
(
new
[]
{
'/'
}));
var
drawable
=
id
.
HasValue
?
ContextCompat
.
GetDrawable
(
ContextHelper
.
Current
,
id
.
Value
)
...
...
@@ -109,13 +114,17 @@ namespace Uno.Helpers
private
static
void
InitializeDrawablesLookup
()
{
if
(
_drawables
is
null
)
{
return
;
}
_drawablesLookup
=
_drawables
.
GetFields
(
BindingFlags
.
Static
|
BindingFlags
.
Public
)
.
ToDictionary
(
p
=>
p
.
Name
,
p
=>
(
int
)
p
.
GetValue
(
null
)
p
=>
(
p
.
GetValue
(
null
)
as
int
?)
??
0
);
}
}
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录