simulate AngularJS button click in c# uwp app - c#

I am trying to create an app that automatically logs me into a webpage.
The page is not mine so I cannot see the code behind it.
http://pcc.magister.net (the page after the first notification screen)
Now I've managed to insert the username and password but I just cannot seem to be capable of triggering a click on the button in the page. I get as far as this :
var functionString = string.Format(#"document.getElementsByClassName('primary-btn ripple')[0].click();");
await Display.InvokeScriptAsync("eval", new string[] { functionString });
But I am getting nothing but errors. 'System.Exception' in System.Private.CoreLib.ni.dll and a 0x80020101 event that is a general javascript error.
The button in DOM explorer looks like this :
<mg-button is-loading="$ctrl.isLoading" caption="doorgaan">
<button class="primary-button ripple" type="submit" ng-class="{'active': $ctrl.isLoading}">
</button></mg-button>
Anybody smarter than me who sees what I'm doing wrong here ?
Here is a minimal c# :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace Test
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
Display.Navigate(new Uri("http://pcc.magister.net/"));
}
private async void NewPageLoaded(WebView sender, WebViewNavigationCompletedEventArgs args)
{
string functionString = "";
if (Display.Source.AbsolutePath.ToString() == "/account/login")
{
functionString = String.Format("document.getElementById('username').innerText = 'testuser'");
try
{
await Display.InvokeScriptAsync("eval", new string[] { functionString });
}
catch
{
//
}
functionString = string.Format("document.getElementsByClassName('primary-btn ripple')[0].click();");
try
{
await Display.InvokeScriptAsync("eval", new string[] { functionString });
}
catch (Exception ezz)
{
Debug.WriteLine("There was an exception!" + ezz);
}
}
}
}
}
And a minimal XAML :
<Page
x:Class="Test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Test"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="0,0,0,0" Name="mainGrid">
<WebView Margin="0,0,0,0" Name="Display" NavigationCompleted="NewPageLoaded"/>
</Grid>
</Page>

Related

Enter or over events are not fired when drag and drop is done on UWP

I'm making a desktop app with UWP for Windows. I was making drag and drop features, but it doesn't work. When I drag a file, it keeps showing "Not allowed" symbol,🚫. Drag events and over events seem not to be fired. Any help is greatly appreciated. I'm not running Visual Studio 2022 as an admin.
Mainpage.xamc.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace XML2PDFConverter
{
/// <summary>
/// Starting from a blank page.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void BackgroundGrid_DragEnter(object sender, DragEventArgs e)
{
e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Move;
}
private async void BackgroundGrid_Drop(object sender, DragEventArgs e)
{
if (e.DataView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
{
var items = await e.DataView.GetStorageItemsAsync();
var filePaths = items.Select(x => x.Path).ToList();
}
}
private void BackgroundGrid_DragOver(object sender, DragEventArgs e)
{
e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Move;
}
}
}
MainPage.xaml
<Page
x:Class="XMLToPDFConverter.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="XMLToPDFConverter"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="BackgroundGrid" AllowDrop="True" DragEnter="BackgroundGrid_DragEnter" Drop="BackgroundGrid_Drop" DragOver="BackgroundGrid_DragOver" />
</Page>
The problem is, that your grid does not have a background color. It is enought to set the background color to transparent and it will work as expected:
<Grid x:Name="BackgroundGrid" Background="Transparent" AllowDrop="True" DragEnter="BackgroundGrid_DragEnter" Drop="BackgroundGrid_Drop" DragOver="BackgroundGrid_DragOver" />

Binding main class fails

i created a custom control in WPF for Windows 10 Apps. The problem is that the binding in the main class doesn't work. It binds to my custom control. Can anyone see the problem? How can i repair the code. It doesnt work. Specially the binding doesnt work. How can i solve that. I have no idea, how to fix that.
View Model
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using AppDemo.Annotations;
namespace AppDemo
{
public class ViewModel : INotifyPropertyChanged
{
private String t1, t2;
public String T1
{
get { return t1; }
set
{
t1 = value;
Concat = T1 + T2;
}
}
public String T2
{
get { return t2; }
set
{
t2 = value;
Concat = T1 + T2;
}
}
private String concat;
public String Concat
{
get { return concat; }
set
{
concat = value;
OnPropertyChanged(nameof(Concat));
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
<UserControl
x:Class="AppDemo.ExampleControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid Name="grid">
<StackPanel>
<TextBox Text="{Binding T1,Mode=TwoWay}"/>
<TextBox Text="{Binding T2,Mode=TwoWay}"/>
</StackPanel>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using AppDemo.Annotations;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace AppDemo
{
public sealed partial class ExampleControl : UserControl
{
public static readonly DependencyProperty ConcatProperty = DependencyProperty.Register(
"Concat", typeof(String), typeof(ExampleControl), new PropertyMetadata(default(String)));
private ViewModel m;
public String Concat
{
get { return (String)GetValue(ConcatProperty); }
set { SetValue(ConcatProperty, value); }
}
public ExampleControl()
{
this.InitializeComponent();
m = new ViewModel();
grid.DataContext = m;
m.PropertyChanged += M_PropertyChanged;
}
private void M_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Concat = m.Concat;
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
<Page
x:Class="AppDemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel>
<local:ExampleControl Concat="{Binding C}"/>
<Button Name="btnTest" Click="BtnTest_OnClick">Test</Button>
</StackPanel>
</Grid>
</Page>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace AppDemo
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public String C { get; set; }
public MainPage()
{
this.InitializeComponent();
this.DataContext = this;
}
private void BtnTest_OnClick(object sender, RoutedEventArgs e)
{
String msg = C;
}
}
}
It is generally better to put your properties that you want to bind to, within their own distinct view-model class - not mixed in with your view code. This code is unnecessarily obtuse.
BTW...
Your UserControl named ExampleControl, has textboxes whose Text property is bound to T1 and T2. However, when you set either of those values - they set the Concat property but fail to raise the PropertyChanged event with their own name.
You'd fix that with, for example:
public String T1
{
set
{
t1 = value;
OnPropertyChanged(nameof(T1));
Concat = T1 + T2;
}
}
Set the Mode of the Binding to TwoWay in your MainPage:
<local:ExampleControl Concat="{Binding C, Mode=TwoWay}"/>

UWP ComboBox not populating with bound value

I'm writing a UWP app and have a few comboboxes bound to my view model. For some reason the comboboxes aren't updating the bound value nor loading it when they render if I set the values manually while debugging. I see that this is a common issue but I can't spot any of the causes I've seen other people have so far. Following is my stripped down code:
XAML:
<Page
x:Class="UWPApp.Scorekeeper.SelectGoalTime"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UWPApp.Scorekeeper"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Name="MainElement">
<Grid Background="{ThemeResource SystemControlBackgroundAccentBrush}">
<ComboBox x:Name="MinutesSelect" SelectedValue="{Binding ElementName=MainElement,Path=ViewModel.Minutes}" ItemsSource="{Binding ElementName=MainElement,Path=MinutesList}"/>
</Grid>
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using UWPApp.Scorekeeper.Interfaces;
using UWPApp.Scorekeeper.Models.ViewModels;
using UWPApp.Scorekeeper.Models.TransportClasses;
using Windows.UI.Popups;
using UWPApp.Scorekeeper.Models;
using UWPApp.Scorekeeper.Toolbox;
namespace UWPApp.Scorekeeper
{
public sealed partial class SelectGoalTime : Page
{
public AddGoal_FVM ViewModel { get; set; }
public List<int> MinutesList { get; set; } = Enumerable.Range(0,21).ToList();
public SelectGoalTime()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var message = e.Parameter as GoalMessage;
ViewModel = message.ViewModel;
}
}
}
AddGoal_FVM
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace UWPApp.Scorekeeper.Models.ViewModels
{
public class AddGoal_FVM
{
public int Minutes { get; set; }
}
}
Since I don't have the reputation to add a comment, I'll have to share this way:
Found here, https://twitter.com/kdawg02/status/746734845393518592, BUG UWP ComboBox SelectedValue has to be the last property in XAML otherwise it will not set the value on load.
Hope it helps, I had no end of troubles with trying to bind a combobox in UWP with the MVVM pattern.

WPF Custom control in WinForms with floating precision size

I was wondering is it possible to create a panel-like control in wpf, and another wpf custom control that will be the child of this panel, all in WinForms application. And then, would it be possible to set the custom control's size in float?
Also would I be able to rotate that custom control?
Thanks in advance
You will need to use the System.Windows.Forms.Integration NameSpace, more specifically the ElementHost Control, that will allow you to embed a WPF Control in Winforms.
This is a quick and simple demonstration of changing the WPF UserControls Child UserControls Size and Location. I will leave the animation to you.
Main Winform Form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
ElementHost host;
WpfControlLibrary1.UserControl1 uc;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
host = new ElementHost();
host.Dock = DockStyle.Top;
uc = new WpfControlLibrary1.UserControl1();
host.Child = uc;
this.Controls.Add(host);
}
private void button1_Click(object sender, EventArgs e)
{
uc.SetChildLocation = new System.Windows.Point(uc.SetChildLocation.X + 25.5, uc.SetChildLocation.Y + 10.2);
}
private void button2_Click(object sender, EventArgs e)
{
uc.SetChildSize = new System.Windows.Size(uc.SetChildSize.Width + .25, uc.SetChildSize.Height + .25);
}
}
}
UserControl1.xaml
<UserControl x:Class="WpfControlLibrary1.UserControl1"
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:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Background="Red" xmlns:my="clr-namespace:WpfControlLibrary1">
<Canvas>
<my:UserControl2 HorizontalAlignment="Center" x:Name="userControl21" VerticalAlignment="Center" Canvas.Left="0" Canvas.Top="0" />
</Canvas>
</UserControl>
UserControl1.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;
namespace WpfControlLibrary1
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public Point SetChildLocation
{
get
{
return new Point(Canvas.GetLeft(userControl21), Canvas.GetTop(userControl21));
}
set
{
Canvas.SetLeft(userControl21, value.X);
Canvas.SetTop(userControl21, value.Y);
}
}
public Size SetChildSize
{
get
{
return new Size(userControl21.ActualWidth, userControl21.ActualHeight);
}
set
{
userControl21.Width = value.Width;
userControl21.Height = value.Height;
}
}
}
}
UserControl2.xaml
<UserControl x:Class="WpfControlLibrary1.UserControl2"
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:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" SizeChanged="UserControl_SizeChanged">
<Grid>
<Rectangle x:Name="rect" Fill="Blue" Height="40" Width="120"></Rectangle>
</Grid>
</UserControl>
UserControl2.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;
namespace WpfControlLibrary1
{
/// <summary>
/// Interaction logic for UserControl2.xaml
/// </summary>
public partial class UserControl2 : UserControl
{
public UserControl2()
{
InitializeComponent();
}
private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
rect.Width = e.NewSize.Width;
rect.Height = e.NewSize.Height;
}
}
}

Binding to User Control Properties in an Items Control

Can someone tell me why the way I am binding data here does not work? I was able to do this fine with using a GridView. I am not sure why the data is not being passed to the user control here, in addition it compiles fine and shows the user controls with there default text
Main.xaml.cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace ItemsControlSample
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
PopulateData();
}
public class someKindaOfDataHolder
{
public string Text1;
public string Text2;
}
private void PopulateData()
{
List<someKindaOfDataHolder> dataAndStuff = new List<someKindaOfDataHolder>();
for (int i = 0; i < 5; ++i)
{
dataAndStuff.Add(new someKindaOfDataHolder()
{
Text1 = "data spot 1: " + i.ToString(),
Text2 = "data spot 2: " + (i + 2).ToString()
});
}
ListOfAUserControls.ItemsSource = dataAndStuff;
}
}
}
Main.xaml
<Page
x:Class="ItemsControlSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ItemsControlSample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<ScrollViewer>
<ItemsControl x:Name="ListOfAUserControls" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:CustomUserControl DynamicText1Text="{Binding Text1}" DynamicText2Text="{Binding Text2}" Margin="0,0,10,0"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="100,46,-50,0"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</Grid>
</Page>
CustomUserControl.xaml.cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
namespace ItemsControlSample
{
public sealed partial class CustomUserControl : UserControl
{
public static readonly DependencyProperty DynamicText1Property =
DependencyProperty.Register("DynamicText1Text", typeof(string), typeof(CustomUserControl), new PropertyMetadata(null, OnDynamicText1PropertyChanged));
public string DynamicText1Text
{
get { return (string)GetValue(DynamicText1Property); }
set { SetValue(DynamicText1Property, value); }
}
public static readonly DependencyProperty DynamicText2Property =
DependencyProperty.Register("DynamicText2Text", typeof(string), typeof(CustomUserControl), new PropertyMetadata(null, OnDynamicText2PropertyChanged));
public string DynamicText2Text
{
get { return (string)GetValue(DynamicText2Property); }
set { SetValue(DynamicText2Property, value); }
}
public CustomUserControl()
{
this.InitializeComponent();
}
private static void OnDynamicText1PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var obj = d as CustomUserControl;
obj.DynamicText1.Text = e.NewValue.ToString();
}
private static void OnDynamicText2PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var obj = d as CustomUserControl;
obj.DynamicText2.Text = e.NewValue.ToString();
}
}
}
CustomUserControl.xaml:
<UserControl
x:Class="ItemsControlSample.CustomUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ItemsControlSample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="800"
d:DesignWidth="800">
<Grid Background="Blue">
<Grid.RowDefinitions>
<RowDefinition Height="6*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Image Source="ms-appx:///Assets/MSIcon.png" />
<StackPanel Grid.Row="1" Margin="25">
<TextBlock Text="Obay" FontSize="45" />
<TextBlock x:Name="DynamicText1" Text="DynamicText1" FontSize="35" />
<TextBlock x:Name="DynamicText2" Text="DynamicText2" FontSize="35" />
</StackPanel>
</Grid>
</UserControl>
Thanks!
You need to set the DataContext somewhere. Without it - your bindings have no context and they fail (look at the Output window in VS when debugging Debug builds to see binding errors). You are setting ItemsSource="{Binding}" where the binding has no context.
Then again - you are overriding the ItemsSource elsewhere with your "ListOfAUserControls.ItemsSource = dataAndStuff;" call, so that is likely not the issue causing your problem in the end. The DataContext of an item in an ItemsControl should be set automatically to an item in the ItemsSource collection.
Another problem that might block you there is that someKindaOfDataHolder.Text1 in your case is a field and it should be a property to work with bindings - try this instead:
public string Text1 { get; set; }

Categories