我试图通过开发一个小型的“网络爬虫”来接触一些 F# 语言。我有一个这样声明的函数:
let results = HtmlDocument.Load("http://joemonster.org//")
let images =
results.Descendants ["img"]
|> Seq.map (fun x ->
x.TryGetAttribute("src").Value.Value(),
x.TryGetAttribute("alt").Value.Value()
)
Run Code Online (Sandbox Code Playgroud)
这当然应该为我返回“img”标签的“src”和“alt”属性映射。但是,当我遇到标签中缺少其中一个的情况时,我收到了TryGetAttribute返回 null的异常。我想更改该函数以在 null 的情况下返回属性值或空字符串。我已经尝试了这张票的答案,但没有成功。
我正在编写一个小型UWP项目,也使用MVVM模式(MVVM Light框架)进行研究,并在许多场景和控件中遇到了绑定问题.
我已经努力将其中一个分离成这里提供的迷你示例项目.
ProgressRing控件的IsActive属性对ViewModel方面的更新没有做出反应,即使它具有:
MainPage.xaml中
<Page
x:Class="TestProgressRing.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:local="using:TestProgressRing"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Width="491.282"
Height="492.308"
DataContext="{Binding MainPageViewModel, Source={StaticResource ResourceKey=Locator}}"
mc:Ignorable="d">
<Grid
Width="500"
Height="800"
Margin="0,0,-8.667,-307.667"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="3*" />
</Grid.RowDefinitions>
<Button
Grid.Row="0"
Width="250"
Height="50"
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="Boom">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:InvokeCommandAction Command="{Binding ClickCommand}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</Button>
<ProgressRing
Grid.Row="1"
Width="500"
Height="500"
Margin="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
IsActive="{Binding IsLoading, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
Visibility="Visible" />
</Grid>
</Page>
Run Code Online (Sandbox Code Playgroud)
MainPageViewModel.cs
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command; …Run Code Online (Sandbox Code Playgroud)