重现步骤:
history.length- 它将显示选项卡 #1 的历史记录。另外,history.go(-1)将转到选项卡 #2 中的页面 #1发生这种情况可能是因为 iOS 试图为用户保持流畅的体验(如果页面打开新选项卡的链接,您仍然可以通过 UI 按钮导航回来,这将关闭新选项卡并返回到上一个选项卡)。
我想问一下:
history.length == 1,但这里没有)?如果我想帮助用户返回,这将很有帮助,因为我需要做window.close()(=关闭选项卡#2)而不是history.go(-1)(=在选项卡#2中打开页面#1)。谢谢!
我想用几个Rectangle()s 覆盖我的图像,它应该响应手势(如点击或拖动)。但是,我发现当我清除矩形时,它会停止接收手势。
Rectangle()
.fill(.clear)
.gesture(
LongPressGesture()
.onEnded { value in
// this isn't called when the rectangle fill is .clear
}
)
Run Code Online (Sandbox Code Playgroud)
有没有办法让不可见的元素接收点击?我知道我可以给它 1% 的不透明度,但这感觉像是一个丑陋的(而且可见的)拼凑。
我正在创建一个改变Button的ControlTemplate的样式(它实际上在右边添加了箭头,因此按钮看起来像下拉按钮(在wpf中缺少)).
在模板内部,我放了实际按钮(因为我需要结果仍然像按钮 - 我只能更改ContentTemplate,但我需要与箭头一起显示实际内容,并将ContentPresenter放在ContentTemplate中产生堆栈溢出 - wpf just将模板扩展到演示者并继续和箭头一起继续.
我的问题是我希望用户能够更改按钮的背景,所以我需要绑定Background="{TemplateBinding Background}".有了这个,用户必须始终提供背景,否则它将为null.为了防止这种情况,我理解我需要为后台提供默认值,所以我补充说<Setter Property="Background" Value="default Background goes here"/>
问题是,这个二传手应该是什么价值?我假设wpf的内置样式是为每个应用程序自动加载的,我已经查看了aero.normalcolor.xaml,它们提供了ButtonNormalBackground样式,后来将它用作默认按钮样式<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>(aero.normalcolor.xaml,第47行).
正是我想要的,但是,当我使用这个setter时,找不到静态资源.然后我将其更改为DynamicResource,但在这种情况下,按钮的背景保持透明 - 不使用ButtonNormalBackground!
我应该如何提供系统的按钮外观作为默认值?谢谢!
PS:对于BorderBrush,BorderThickness - geez的dtto,似乎我不允许WPF作者一直使用的技巧:/
我的风格:
<Style TargetType="{x:Type ToggleButton}" x:Key="DropDownArrowStyle">
<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
<Setter Property="ToggleButton.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<ToggleButton
x:Name="PART_ToggleButton"
Margin="{TemplateBinding Margin}"
Padding="{TemplateBinding Padding}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
IsEnabled="{TemplateBinding IsEnabled}"
IsChecked="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
ContextMenu="{TemplateBinding ContextMenu}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Foreground="{TemplateBinding Foreground}"
FocusVisualStyle="{TemplateBinding FocusVisualStyle}"
ClickMode="{TemplateBinding ClickMode}" …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何将DispatcherObject(在我的案例中为BitmapSource)复制到另一个线程中.
使用案例:
我有一个需要在新线程中显示窗口的WPF应用程序(该应用程序实际上是Outlook插件,我们需要这样做,因为Outlook在主UI线程中有一些钩子并且正在窃取我们需要使用的某些热键 - 在Outlook,WPF(我们用于UI)和Winforms(我们需要使用某些微软提供的winforms控件)的互操作中"丢失翻译").
有了这个,我有WPFMessageBox的实现,通过设置一些静态属性来配置 - 其中一个是图标的BitmapSource.这样使用,以便在启动时我可以设置一次WPFMessageBox.Icon,从那时起,每个WPFMessageBox将具有相同的图标.
问题是分配给图标的BitmapSource是DispatcherObject,当读取时,它将抛出InvalidOperationException:"调用线程无法访问此对象,因为不同的线程拥有它.".
如何将BitmapSource克隆到实际线程中?它有Clone()和CloneCurrentValue()方法,它们不起作用(它们也抛出相同的异常).我也发现使用originalIcon.Dispatcher.Invoke(在这里进行克隆) - 但BitmapSource的Dispatcher为null,仍然 - 我在错误的线程上创建了一个副本,但仍然无法在我的上使用它.BitmapSource.IsFrozen == true.
关于如何将BitmapSource复制到不同的线程(没有从新线程中的图像文件完全重构)的任何想法?
编辑: 所以,冻结没有帮助:最后我有一个BitmapFrame(Window.Icon无论如何也不会采用任何其他类型的ImageSource),当我在另一个线程上将其指定为Window.Icon时,即使冻结,我得到InvalidOperationException:"调用线程无法访问此对象,因为另一个线程拥有它." 具有以下堆栈跟踪:
WindowsBase.dll!System.Windows.Threading.Dispatcher.VerifyAccess() + 0x4a bytes
WindowsBase.dll!System.Windows.Threading.DispatcherObject.VerifyAccess() + 0xc bytes
PresentationCore.dll!System.Windows.Media.Imaging.BitmapDecoder.Frames.get() + 0xe bytes
PresentationFramework.dll!MS.Internal.AppModel.IconHelper.GetIconHandlesFromBitmapFrame(object callingObj = {WPFControls.WPFMBox.WpfMessageBoxWindow: header}, System.Windows.Media.Imaging.BitmapFrame bf = {System.Windows.Media.Imaging.BitmapFrameDecode}, ref MS.Win32.NativeMethods.IconHandle largeIconHandle = {MS.Win32.NativeMethods.IconHandle}, ref MS.Win32.NativeMethods.IconHandle smallIconHandle = {MS.Win32.NativeMethods.IconHandle}) + 0x3b bytes
> PresentationFramework.dll!System.Windows.Window.UpdateIcon() + 0x118 bytes
PresentationFramework.dll!System.Windows.Window.SetupInitialState(double requestedTop = NaN, double requestedLeft = NaN, double requestedWidth = 560.0, double requestedHeight = NaN) + 0x8a bytes
PresentationFramework.dll!System.Windows.Window.CreateSourceWindowImpl() + …Run Code Online (Sandbox Code Playgroud) 我有Textsinside VStack,我想在它们之间添加一些空白。
但是,设置最小可能的填充 (= 1) 会创建太大的填充,而填充为零则根本不会创建任何填充。
SwiftUI 似乎以某种方式计算realPadding = declaredPadding > 0 ? declaredPadding + 8 : 0,这使得较小的填充无法实现。
为什么会发生这种情况?这种行为实际上记录在某处吗?
现在看来,如果我想要例如。文本之间有2pt的差距,我运气不好。
有没有办法真正让文本视图之间的填充比我得到的更小.padding(.bottom, 1)?
Nikita Tonsky批评了这种“自动”行为,但他没有提出解决方案。
要粘贴到游乐场的示例代码:
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
VStack {
VStack{
Text("Hello World")
.background(Color.red)
.padding(.bottom, 0)
Text("padding 0")
.background(Color.red)
}
.padding()
VStack{
Text("Hello World")
.background(Color.red)
.padding(.bottom, 1)
Text("padding 1 - a huge step-up from 0, why?")
.background(Color.red)
}
.padding()
VStack{
Text("Hello …Run Code Online (Sandbox Code Playgroud)