我正在学习WPF WebView控件,我有以下MainWindow.xaml文件:
<Window x:Class="MyWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MyWPF"
xmlns:WPF="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls.WebView"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid x:Name="Grid1" Grid.Row="1" Grid.Column="1">
<WPF:WebView x:Name="webView1"
Grid.Row="0"
Grid.Column="0"
Loaded="WebView_Loaded" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
以及下面的相应MainWindow.xaml.cs文件:
namespace MyWPF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
webView1.Navigate(new Uri("https://www.google.com"));
}
private void WebView_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我没有收到任何预期的弹出窗口。如果我删除
webView1.Navigate(new Uri(" https://www.google.com "));
我可以得到一个空白的弹出窗口。我的代码有什么问题以及如何解决?
更新1
我添加了Window_Loaded事件处理程序并在其中移动了以下两个事件处理程序,现在我可以看到一个空白的弹出窗口,但没有任何内容和消息框。
Uri uri = new Uri("https://www.google.com");
WebView1.Navigate(uri);
Run Code Online (Sandbox Code Playgroud)
整个更新的代码隐藏:
namespace MyWPF
{
/// <summary> …Run Code Online (Sandbox Code Playgroud) I want to implement margin-right inline CSS to the below react span element:
import React, { Component } from "react";
class NavBar extends Component {
state = {
totalCounters: 0,
};
render() {
let styles = {
margin-right: '20px',
width: '250px',
height: '250px',
backgroundColor: 'yellow',
};
return (
<nav className="navbar navbar-light bg-light">
<a className="navbar-brand" href="#">
Navbar
</a>
<span style={styles} className="badge badge-pill badge-secondary">
{this.props.totalCounters}
</span>
</nav>
);
}
}
export default NavBar;
Run Code Online (Sandbox Code Playgroud)
But it shows syntax error, while no error if …
我正在学习 UWP 用户控制并面临以下代码:
<Page
x:Class="LearningUWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:LearningUWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<local:MyUserControl Username="aaa" Password="bbb" fillcolor="Blue" />
</StackPanel>
</Page>
Run Code Online (Sandbox Code Playgroud)
我定义了一个具有三个依赖属性的用户控件:用户名、密码和填充颜色。下面的代码显示了我的用户控件 xaml
<UserControl
x:Name="myctrl"
x:Class="LearningUWP.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:LearningUWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>
<RelativePanel>
<Rectangle Fill="{Binding fillcolor, ElementName=myctrl}" x:Name="Rec" Height="100" RelativePanel.AlignRightWithPanel="True" />
<TextBlock Text="Username_lbl" RelativePanel.AlignRightWithPanel="True" TextAlignment="Center" RelativePanel.Below="Rec" x:Name="Username_lb" Margin="0,50,0,0" RelativePanel.AlignLeftWithPanel="True" />
<TextBox x:Name="Username_input" RelativePanel.Below="Username_lb" RelativePanel.AlignRightWithPanel="True" RelativePanel.AlignLeftWithPanel="True" Margin="0,20,0,0" Text="{Binding Username, ElementName=myctrl}" ></TextBox>
<TextBlock Text="Password_lbl" x:Name="Password_lb" RelativePanel.AlignRightWithPanel="True" TextAlignment="Center" RelativePanel.Below="Username_input" RelativePanel.AlignLeftWithPanel="True" Margin="0,20,0,0" ></TextBlock>
<TextBox x:Name="Password_input" RelativePanel.Below="Password_lb" RelativePanel.AlignRightWithPanel="True" RelativePanel.AlignLeftWithPanel="True" Margin="0,20,0,0" Text="{Binding Password, ElementName=myctrl}" ></TextBox> …Run Code Online (Sandbox Code Playgroud)