正在請求幫助我如何動態更改DataTemplate中包含的ImageBrush的ImageSource值。如何更改DataTemplate中ImageBrush的ImageSource值
下面是我的XAML代碼:
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<TextBlock Text="{x:Bind first_name}"
Name="TxtFirstName"
Margin="10,0,0,0"
FontSize="18" FontWeight="Bold" FontStyle="Italic"/>
<TextBlock Text="{x:Bind last_name}"
Name="TxtLastName"
Margin="10,0,0,0"
FontSize="18" FontWeight="Bold" FontStyle="Italic"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Margin="0,40,0,0" HorizontalAlignment="Left" >
<Ellipse Width="200" Height="200" Name="ProfilePicEllipse">
<Ellipse.Fill>
<ImageBrush x:Name="ProfilePic"
ImageSource="{x:Bind image_url}" />
</Ellipse.Fill>
</Ellipse>
<Image x:Name="ResultImage" Stretch="UniformToFill"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Margin="0,40,0,0">
<TextBlock Text= "{x:Bind profile}"
VerticalAlignment="Center"
Margin="10,0,0,0"
FontSize="18" />
</StackPanel>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
你到底想幹什麼?您已經將ImageSource綁定到一個屬性,因此更改該屬性(image_url)的值應該可以做到這一點!但不要忘記添加Mode = OneWay來啓用更改跟蹤 – Depechie
@Depechie爲什麼不把它寫成答案? – Clemens
@Clemens老實說,因爲我不確定他面臨的實際問題是什麼:)但可能只是模式......我會添加答案。 – Depechie