Ich brauche Ihren Vorschlag und Hilfe bitte. Ich habe bereits eine Windows Phone 8.1-Anwendung und ich muss es in UWP konvertieren.Problem in UserControl von Windows Phone 8.1 in universelle Anwendung konvertieren 10
Meine Frage bezieht sich auf usercontrol benutzerdefinierte Bild-Taste: wie man es konvertiert und was ist der beste Weg, um solche Kontrolle über UWP zu haben.
Das ist mein Windows Phone 8-Code: -
XAML: -
<UserControl x:Class="CustomizedPopup.ImageButton.ImageButtonControl">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--<Image x:Name="Image" Stretch="Fill" Width="auto" Grid.Row="0"/>-->
<TextBlock x:Name="TextBlock" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center" />
</Grid>
</UserControl>
CS-Datei: -
namespace CustomizedPopup.ImageButton
{
public partial class ImageButtonControl : UserControl
{
public ImageButtonControl()
{
InitializeComponent();
}
ImageSource source;
public event EventHandler Click;
Double textfontsize;
public Double TextFontSize
{
get { return textfontsize; }
set { textfontsize = value; TextBlock.FontSize = textfontsize; }
}
public ImageSource Source
{
get { return source; }
set
{
source = value;
System.Windows.Media.ImageBrush myBrush = new System.Windows.Media.ImageBrush();
Image image = new Image();
image.Source = source;// new System.Windows.Media.Imaging.BitmapImage(new Uri(@"/Assets/bg/bg1.jpg/", UriKind.RelativeOrAbsolute));
myBrush.ImageSource = image.Source;
myBrush.Stretch = Stretch.Uniform;
LayoutRoot.Background = myBrush;
//Image.Source = source;
}
}
public ImageSource PressedSource { get; set; }
string text;
public string Text
{
get { return text; }
set { text = value; TextBlock.Text = text; }
}
protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
System.Windows.Media.ImageBrush myBrush = new System.Windows.Media.ImageBrush();
Image image = new Image();
image.Source = PressedSource;// new System.Windows.Media.Imaging.BitmapImage(new Uri(@"/Assets/bg/bg1.jpg/", UriKind.RelativeOrAbsolute));
myBrush.ImageSource = image.Source;
myBrush.Stretch = Stretch.Uniform;
LayoutRoot.Background = myBrush;
}
protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
{
base.OnMouseLeave(e);
System.Windows.Media.ImageBrush myBrush = new System.Windows.Media.ImageBrush();
Image image = new Image();
image.Source = Source;// new System.Windows.Media.Imaging.BitmapImage(new Uri(@"/Assets/bg/bg1.jpg/", UriKind.RelativeOrAbsolute));
myBrush.ImageSource = image.Source;
myBrush.Stretch = Stretch.Uniform;
LayoutRoot.Background = myBrush;
}
protected override void OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
//Image.Source = Source;
System.Windows.Media.ImageBrush myBrush = new System.Windows.Media.ImageBrush();
Image image = new Image();
image.Source = Source;// new System.Windows.Media.Imaging.BitmapImage(new Uri(@"/Assets/bg/bg1.jpg/", UriKind.RelativeOrAbsolute));
myBrush.ImageSource = image.Source;
myBrush.Stretch = Stretch.Uniform;
LayoutRoot.Background = myBrush;
if (Click != null)
Click(this, EventArgs.Empty);
//Image.Stretch = Stretch.Uniform;
}
}
}