WPF und C-Sharp Binding a Variable
Hallo, ich habe vor kurzem beschlossen mir mal wider was neues anzuschauen(C# und WPF). Doch nun stehe ich schon vor einem Problem das ich leider nicht selbst lösen kann.
Ich möchte aus dem Registry Key: HKEY_Current_User\Software\Car\ den Wert des Schlüssels "MARKE_IMAGE" auslesen und diesen Pfad im XAML als Pfad zu einem Bild verwenden. Allerdings bekomme ich statt des Bildes nur eine leere Stelle. Ich denke mein Problem liegt irgendwo beim übergeben an IMAGE_NAME. Ich hoffe irgendwer kann mir hier etwas weiterhelfen.
page1.xaml.cs
page1.caml
Was mache ich hier falsch?
Danke schonmal für die Hilfe
mfg
page1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Security.Permissions;
using Microsoft.Win32;
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,
ViewAndModify = "HKEY_CURRENT_USER")]
namespace TEST_0_1
{
public partial class TEST : Page
{
public class IMAGE
{
private string _IMAGE;
public string GET_IMAGE()
{
RegistryKey rk =
Registry.CurrentUser.OpenSubKey
(@"Software\CAR");
string GET_IMAGE = (string)rk.GetValue("MARKE_IMAGE");
rk.Close();
return _IMAGE;
}
public string IMAGE_NAME
{
get { return _IMAGE; }
set { _IMAGE = value; }
}
}
}
page1.caml
<Page x:Class="TEST_0_1.TEST"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:my="clr-namespace:TEST_0_1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="480" d:DesignWidth="640"
Title="Home">
<Grid x:Name="LayoutRoot" HorizontalAlignment="Center" VerticalAlignment="Center" Width="640" Height="480">
<Grid.Resources>
<my:IMAGE x:Key="myIMAGE" IMAGE_NAME="Spot"/>
</Grid.Resources>
<Image HorizontalAlignment="Right" Margin="0,115,70,115" Width="200" Height="200" Source="{Binding IMAGE_NAME, Mode=Default}" DataContext="{StaticResource MyIMAGE}" Stretch="Fill"/>
</Grid>
Was mache ich hier falsch?
Danke schonmal für die Hilfe
mfg
Please also mark the comments that contributed to the solution of the article
Content-Key: 183624
Url: https://administrator.de/contentid/183624
Printed on: April 20, 2024 at 00:04 o'clock
4 Comments
Latest comment