adding controls to grid using xml file - c#

this code converts any controls or object to xml
if I saved this
the saved xml would be looks like:
<Grid Name="g" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Image Source="pack://application:,,,/WpfApplication1;component/Images/Picture3.jpg" Stretch="Fill" Name="image1" Width="200" Height="150" Margin="96,36,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
<Button Name="button1" Width="75" Height="23" Margin="352,71,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">Button</Button>
<TextBox Name="textBox1" Width="120" Height="23" Margin="62,198,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" xml:space="preserve" />
<Label Name="label1" Height="28" Margin="270,213,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">Label</Label>
</Grid>
I used this code to save this:
System.IO.StreamWriter s = new System.IO.StreamWriter(#"d:\grid.xml");
s.WriteLine(System.Windows.Markup.XamlWriter.Save(g));
s.Close();
g is the name of the grid which contains all controls
my question:
can I reverse this, read this xml file and represent it on a window

Just use the XAML Reader Class.

var somecontrol = XamlReader.Load(#"<ItemsPanelTemplate
xmlns=""http://schemas.microsoft.com/client/2007""
xmlns:toolkit=""http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"">
<toolkit:WrapPanel /></ItemsPanelTemplate>");

Related

Refresh Button UWP

I want to add a refresh button to my app so that I don't always have to quit the app to clear the data.
I have tried a RefreshRequested, but I can't make it work.
C# code:
private void RefreshButtonClick(object sender, RoutedEventArgs e)
{
RefreshContainer.requestRefresh();
}
<RefreshContainer>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="910" Height="383" Margin="0,0,0,0">
<RelativePanel
HorizontalAlignment="Center" BorderBrush="DarkOliveGreen" BorderThickness="8" Background="FloralWhite" Height="356" VerticalAlignment="Center" Width="871" Margin="0,0,0,0" Visibility="Visible" RequestedTheme="Default">
<AppBarButton x:Name="RefreshButton" Click="RefreshButtonClick"
Icon="Refresh" Label="Refresh" HorizontalAlignment="Left" Margin="155,178,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="timerLabel" HorizontalAlignment="Left" Text="00:00:00" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="72" FontWeight="Normal" TextAlignment="Center" Width="328" Margin="272,90,0,0"/>
<Button Name="startButton" Background="MediumSeaGreen" Foreground="White" Content="Start" HorizontalAlignment="Left" Click="Button_Click_Start" VerticalAlignment="Top" Margin="311,219,0,0"/>
<Button Name="stopButton" Background="MediumSeaGreen" Foreground="White" Content="Pause" HorizontalAlignment="Left" Click="Button_Click_Pause" VerticalAlignment="Top" Margin="398,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="resetButton" Background="MediumSeaGreen" Foreground="White" Content="Reset" HorizontalAlignment="Left" Click="Button_Click_Reset" VerticalAlignment="Top" Margin="498,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="restButton" Content="Parametres" HorizontalAlignment="Left" Click="Button_Click_Rest" VerticalAlignment="Top" Margin="698,192,0,0" RenderTransformOrigin="1.373,0.57"/>
<TextBlock Name="Round" Text="Nombre Round" HorizontalAlignment="Left" Height="20" Margin="382,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" TextDecorations="Underline"/>
</RelativePanel>
</Grid>
</RefreshContainer>
I expect the app data to refresh
Refresh Button UWP
I tested your code, the problem is you have not set a scroll-able control as RefreshContainer's content. Base on #Stuart Smith provided document, you could realize refresh feature, before that you need place the above Grid content under the ScrollViewer.
Xaml
<RefreshContainer Name="MyRefreshContainer" RefreshRequested="MyRefreshContainer_RefreshRequested">
<ScrollViewer>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Width="910" Height="383" Margin="0,0,0,0">
<RelativePanel
HorizontalAlignment="Center" BorderBrush="DarkOliveGreen" BorderThickness="8" Background="FloralWhite" Height="356" VerticalAlignment="Center" Width="871" Margin="0,0,0,0" Visibility="Visible" RequestedTheme="Default">
<AppBarButton x:Name="RefreshButton" Click="RefreshButtonClick"
Icon="Refresh" Label="Refresh" HorizontalAlignment="Left" Margin="155,178,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="timerLabel" HorizontalAlignment="Left" Text="00:00:00" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="72" FontWeight="Normal" TextAlignment="Center" Width="328" Margin="272,90,0,0"/>
<Button Name="startButton" Background="MediumSeaGreen" Foreground="White" Content="Start" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="311,219,0,0"/>
<Button Name="stopButton" Background="MediumSeaGreen" Foreground="White" Content="Pause" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="398,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="resetButton" Background="MediumSeaGreen" Foreground="White" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="498,219,0,0" RenderTransformOrigin="1.373,0.57"/>
<Button Name="restButton" Content="Parametres" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="698,192,0,0" RenderTransformOrigin="1.373,0.57"/>
<TextBlock Name="Round" Text="Nombre Round" HorizontalAlignment="Left" Height="20" Margin="382,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" TextDecorations="Underline"/>
</RelativePanel>
</Grid>
</ScrollViewer>
</RefreshContainer>
Code behind
private void RefreshButtonClick(object sender, RoutedEventArgs e)
{
MyRefreshContainer.RequestRefresh();
}
private async void MyRefreshContainer_RefreshRequested(RefreshContainer sender, RefreshRequestedEventArgs args)
{
using (var RefreshCompletionDeferral = args.GetDeferral())
{
// Do some async operation to refresh the content
RefreshCompletionDeferral.Complete();
RefreshCompletionDeferral.Dispose();
}
}
Tomas, I see you've abandoned the refresh button for now, but I wanted to follow up in case you revisit this later or if others run into this issue in the future.
In order for the data to refresh, you'd need to code this in.
“To get fresh content when needed, handle the RefreshRequested event. In the event handler, you'll need code specific to your app to get the fresh content.” https://learn.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/pull-to-refresh#handle-a-refresh-request. There's a sample in the doc there too.
You'd typically use data binding for this and the RefreshRequested event would need to edit the bound object.
using (var RefreshCompletionDeferral = args.GetDeferral())
{
await FetchAndInsertItemsAsync(3);
}
In the sample, you'll notice that FetchAndInsertItemsAsync is inserting new items to the backing collection.
There's more info on data binding here: https://learn.microsoft.com/en-us/windows/uwp/data-binding/data-binding-quickstart

Add items to combobox in WPF within a canvas

Good day,
I want to add specific items to my combobox, but am running into an error.
Code:
Add-Type -AssemblyName PresentationFramework
[xml]$Form = #"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Printer GUI" Height="465" Width="375">
<Canvas Background="White">
<Label Name="label_username" Content="Username" HorizontalAlignment="Left" Margin="30,30,0,0" VerticalAlignment="Top"/>
<Label Name="label_Location" Content="Select Location" HorizontalAlignment="Left" Margin="170,30,0,0" VerticalAlignment="Top"/>
<TextBox Name="textbox_username" HorizontalAlignment="Left" Height="23" Margin="30,56,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<ComboBox Name="ComboBox_Location" HorizontalAlignment="Left" Margin="170,56,0,0" VerticalAlignment="Top" Width="160"/>
<ComboBoxItem Content="X"/>
<ComboBoxItem Content="Y"/>
<ComboBoxItem Content="Z"/>
</ComboBox>
<Label Name="label_printer" Content="Please select printer from list" HorizontalAlignment="Left" Margin="30,105,0,0" VerticalAlignment="Top"/>
<ComboBox Name="ComboBox_Printer" HorizontalAlignment="Left" Margin="30,131,0,0" VerticalAlignment="Top" Width="300"/>
<CheckBox Name="CheckBox" Content="Check here if you want to add this printer
to your permanent list" HorizontalAlignment="Left" Margin="56,185,0,0" VerticalAlignment="Top" Height="39" Width="245"/>
<Button Name="Button_Add" Content="Add Printer" Margin="140,244,140,150" Width="75" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
<Button Name="Button_XPS" Content="Printer Defaults issue
in Practice Partner" Margin="90,285,90,102" Width="175" Height="40" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" ClickMode="Release" VerticalAlignment="Center"/>
<Button Name="Button_Service" Content="Service call for Printer" Margin="113,343,110,51" Width="130" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
<Button Name="Button_Cancel" Content="Cancel" Margin="140,384,140,10" Width="75" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
</Canvas>
</Window>
"#
$NR=(New-Object System.Xml.XmlNodeReader $Form)
$Win=[Windows.Markup.XamlReader]::Load($NR)
$Win.Showdialog()
As you see, I tried to add items, but the error is as follows;
Cannot convert value "<Window xmlns=...</Window>" to type "System.Xml.XmlDocument".
Error: "The 'Canvas' start tag on line 4 position 6 does not match the end tag of
'ComboBox'. Line 12, position 11."
At H:\Scripts\Form_Main_XAML.ps1:3 char:1
+ [xml]$Form = #"
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException
+ FullyQualifiedErrorId : RuntimeException
This is my first time in Visual Studios, and this code has been a WinForms before this. Thank you all in advance.
Your block that says:
<ComboBox Name="ComboBox_Location" HorizontalAlignment="Left" Margin="170,56,0,0" VerticalAlignment="Top" Width="160"/>
<ComboBoxItem Content="X"/>
<ComboBoxItem Content="Y"/>
<ComboBoxItem Content="Z"/>
</ComboBox>
The first line ends in a />, in which that closing tag designates the end of your ComboBox definition. Instead, you want to end it with > and let your corresponding </ComboBox> line close your block.
Your XAML combobox had a closing tag when it shouldn't:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Printer GUI" Height="465" Width="375">
<Canvas Background="White">
<Label Name="label_username" Content="Username" HorizontalAlignment="Left" Margin="30,30,0,0" VerticalAlignment="Top"/>
<Label Name="label_Location" Content="Select Location" HorizontalAlignment="Left" Margin="170,30,0,0" VerticalAlignment="Top"/>
<TextBox Name="textbox_username" HorizontalAlignment="Left" Height="23" Margin="30,56,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<ComboBox Name="ComboBox_Location" HorizontalAlignment="Left" Margin="170,56,0,0" VerticalAlignment="Top" Width="160">
<ComboBoxItem Content="X"/>
<ComboBoxItem Content="Y"/>
<ComboBoxItem Content="Z"/>
</ComboBox>
<Label Name="label_printer" Content="Please select printer from list" HorizontalAlignment="Left" Margin="30,105,0,0" VerticalAlignment="Top"/>
<ComboBox Name="ComboBox_Printer" HorizontalAlignment="Left" Margin="30,131,0,0" VerticalAlignment="Top" Width="300"/>
<CheckBox Name="CheckBox" Content="Check here if you want to add this printer
to your permanent list" HorizontalAlignment="Left" Margin="56,185,0,0" VerticalAlignment="Top" Height="39" Width="245"/>
<Button Name="Button_Add" Content="Add Printer" Margin="140,244,140,150" Width="75" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
<Button Name="Button_XPS" Content="Printer Defaults issue
in Practice Partner" Margin="90,285,90,102" Width="175" Height="40" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" ClickMode="Release" VerticalAlignment="Center"/>
<Button Name="Button_Service" Content="Service call for Printer" Margin="113,343,110,51" Width="130" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
<Button Name="Button_Cancel" Content="Cancel" Margin="140,384,140,10" Width="75" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
</Canvas>
</Window>

oledbexception is thrown for input that's accepted by access

I'm building a small phonebook application and I'm storing phones in an access database in table called phones whose fields are : FullName,Job,Phone1,Phone2,Notes and SN primary key.
I've set fullname and phone1 to required and set validation rule for fullname to Len([FullName])>3 and validation rule for both phone1 and phone2 to Like "[0-9]*", I also set validation messages for the validation rules.
In a wpf application I've added the access database using visual studio to generate the dataset and tableadapter code, this is MainWindow.xaml:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="253" Width="685">
<Grid Height="206" Width="658">
<Label Content="FullName" Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="Label1" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="78,16,0,0" Name="FullName" VerticalAlignment="Top" Width="185" />
<Label Content="Job" Height="28" HorizontalAlignment="Left" Margin="29,46,0,0" Name="Label2" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="78,46,0,0" Name="Job" VerticalAlignment="Top" Width="185" />
<Label Content="Phone1" Height="28" HorizontalAlignment="Left" Margin="22,75,0,0" Name="Label3" VerticalAlignment="Top" />
<Label Content="Phone2" Height="28" HorizontalAlignment="Left" Margin="269,16,0,0" Name="Label4" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="78,75,0,0" Name="Phone1" VerticalAlignment="Top" Width="110" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="325,21,0,0" Name="Phone2" VerticalAlignment="Top" Width="110" />
<Label Content="Notes" Height="28" HorizontalAlignment="Left" Margin="274,56,0,0" Name="Label5" VerticalAlignment="Top" />
<TextBox Height="95" HorizontalAlignment="Left" Margin="325,60,0,0" Name="Notes" VerticalAlignment="Top" Width="328" AcceptsReturn="True" AcceptsTab="True" />
<Button Content="Save" Height="37" HorizontalAlignment="Left" Margin="274,161,0,0" Name="Button2" VerticalAlignment="Top" Width="135" />
</Grid>
this is save click handler :
private button2_Click(object sender , RoutedEventArgs e)
{
try
{
PhonesDataSetPhonesTableAdapter.Insert(FullName.Text, Job.Text, Phone1.Text, Phone2.Text, Notes.Text);
} catch(OleDbException ex) {
MessageBox.Show(ex.Message);
}
}
the PhonesDataSetPhonesTableAdapter is defined like this :
Global.projectName.PhonesDataSetTableAdapters.PhonesTableAdapter PhonesDataSetPhonesTableAdapter = new Global.projectName.PhonesDataSetTableAdapters.PhonesTableAdapter();
When I launch application and put John as fullname and programmer as job and 2137976 as phone1 number an OleDbException is thrown with the validation message for phone1 which is
your phone number contains letters, it should only contain numbers
but it doesn't contain any letter and when I try the same input through access it accepts it, what's going on here ? and how do I make it work.
The OleDb driver requires a different wildcard character in its Like statement. Instead of * it now wants a % (which is ANSI-92).
If I change in MS Access the validation rule to Like "[0-9]%" I can insert rows with a phonenumber "123" by calling insert on that tableadapter.
The downside of this is that in Access you can no longer insert values as Access now expects the literal character % after a single digit.
If you want both your application and access to work, using the Odbc driver would work.
Here is some background on the issue: Microsoft Jet wildcards: asterisk or percentage sign?

Can't display an image with WPF

I'm creating an app who is a list of choices. For the 3 first choices I want to put 3 images an bellow them 3 radiobutton.
but it only show images when I write :
<Grid>
<Image x:Name="sinus" Source="C:\Users\Maximilien\Documents\BFH\HBridge\HBridge\Resources\sin1.bmp" HorizontalAlignment="Left" Height="100" Margin="120,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<Image x:Name="triangle" Source="C:\Users\Maximilien\Documents\BFH\HBridge\HBridge\Resources\tri1.bmp" HorizontalAlignment="Left" Height="100" Margin="320,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<Image x:Name="continue" Source="C:\Users\Maximilien\Documents\BFH\HBridge\HBridge\Resources\cont1.bmp" HorizontalAlignment="Left" Height="100" Margin="520,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<RadioButton x:Name="sinus_checkbox" HorizontalAlignment="Left" Margin="173,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Sinusoïdale" IsChecked="True"/>
<RadioButton x:Name="triangle_checkbox" HorizontalAlignment="Left" Margin="373,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Triangulaire"/>
<RadioButton x:Name="continue_checkbox" HorizontalAlignment="Left" Margin="573,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Continue"/>
but when I send the .exe to a friend the 3 images wouldn't display..
I've tried this :
<Grid>
<Image x:Name="sinus" Source="pack://siteoforigin:,,,/Resources/sin1.bmp" HorizontalAlignment="Left" Height="100" Margin="120,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<Image x:Name="triangle" Source="pack://siteoforigin:,,,/Resources/tri1.bmp" HorizontalAlignment="Left" Height="100" Margin="320,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<Image x:Name="continue" Source="pack://siteoforigin:,,,/Resources/cont1.bmp" HorizontalAlignment="Left" Height="100" Margin="520,80,0,0" VerticalAlignment="Top" Width="120" Stretch="Fill" />
<RadioButton x:Name="sinus_checkbox" HorizontalAlignment="Left" Margin="173,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Sinusoïdale" IsChecked="True"/>
<RadioButton x:Name="triangle_checkbox" HorizontalAlignment="Left" Margin="373,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Triangulaire"/>
<RadioButton x:Name="continue_checkbox" HorizontalAlignment="Left" Margin="573,200,0,0" VerticalAlignment="Top" Cursor="Hand" ToolTip="Tension Continue"/>
But with that , the 3 images won't even display on my PC and in the debug I got something like : Cannot find a part of the path 'C:\Users\Maximilien\Documents\BFH\HBridge\HBridge\bin\Debug\Resources\sin1.bmp'.
Maybe it's a problem with Ressources but I've set thoses images in the .resx
Thank for answer , I use VS2012 ultimate
Sorry for my english
P.S : some screen :
http://i.stack.imgur.com/8qM82.png
.rar of my project :
http://www.partage-facile.com/V0SQ3J1CU7/hbridge.rar.html
You can try using relative path (relative to your project folder) instead of absolute path like C:\... Assuming that your project folder is C:\Users\Maximilien\Documents\BFH\HBridge\HBridge, this is the relative path to your images :
<Image x:Name="sinus" Source="Resources\sin1.bmp" ..... />
<Image x:Name="triangle" Source="Resources\tri1.bmp" ..... />
<Image x:Name="continue" Source="Resources\cont1.bmp" ..... />
you can also rely on Visual Studio's intellisense to get the correct relative path. When typing Source="" in XAML, with cursor positioned between double-quotes press CTRL+SPACE, dropdown will appear suggesting available paths (tested in VS2012 here)

How to set a datatable to a WPF datagrid C#?

I'm new to c# so go easy.
Basically I build a data table ( and I have verified it's not empty) but it doesn't seem to get displayed in my wpf datagrid... I used this example here and applied it:link text
My datagrid remains blank.
Does that example look fine to you guys?
here is my code:
XACML:
<Window x:Class="WpfApplication1.TickerSearch"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TickerSearch" Height="468" Width="907">
<Grid Background="#E6000000" Name="_grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="244*" />
<ColumnDefinition Width="37*" />
</Grid.ColumnDefinitions>
<TextBox Height="34" HorizontalAlignment="Left" Margin="26,15,0,0" Name="txtSearchTker" VerticalAlignment="Top" Width="225" Grid.ColumnSpan="2" />
<Button Content="Search" Height="32" HorizontalAlignment="Left" Margin="76,160,0,0" Name="btnSearch" VerticalAlignment="Top" Width="124" Click="btnSearch_Click" />
<ListBox Height="114" HorizontalAlignment="Left" Margin="26,224,0,0" Name="lstResults" VerticalAlignment="Top" Width="225" Visibility="Hidden" Grid.ColumnSpan="2" Background="#FFFFB000" />
<Button Content="Select" Height="32" HorizontalAlignment="Left" Margin="76,366,0,0" Name="btnSelect" VerticalAlignment="Top" Width="124" Visibility="Hidden" />
<Label Content="Start Date: " Height="25" HorizontalAlignment="Left" Margin="22,65,0,0" Name="label1" VerticalAlignment="Top" Width="71" Background="#00FFB000" FontFamily="Georgia" Foreground="#FFFFB000" />
<Label Content="End Date:" Height="27" HorizontalAlignment="Left" Margin="22,93,0,0" Name="label2" VerticalAlignment="Top" Width="71" Background="#00FFB000" FontFamily="Georgia" Foreground="#FFFFB000" />
<DatePicker Height="22" HorizontalAlignment="Left" Margin="93,65,0,0" Name="dateFrom" VerticalAlignment="Top" Width="138" />
<DatePicker Height="22" HorizontalAlignment="Left" Margin="93,94,0,0" Name="toDate" VerticalAlignment="Top" Width="138" />
<Label Content="Just Today" Height="27" HorizontalAlignment="Left" Margin="22,122,0,0" Name="label3" VerticalAlignment="Top" Width="71" Background="#00FFB000" FontFamily="Georgia" Foreground="#FFFFB000" />
<CheckBox Content="CheckBox" Height="17" HorizontalAlignment="Left" Margin="93,127,0,0" Name="chkBoxToday" VerticalAlignment="Top" Width="15" />
<DataGrid AutoGenerateColumns="False" Height="315" HorizontalAlignment="Left" Margin="285,68,0,0" x:Name="_dataGrid" VerticalAlignment="Top" Width="468" ItemsSource="{Binding Path=.}" Background="#C6F7F700"></DataGrid>
</Grid>
c#:
_ds = new DataSet();
DataTable table = yahooFinance.lookupSymbol();
_ds.Tables.Add(table);
_grid.DataContext = _ds.Tables[0];
Change it to ItemsSource="{Binding}".
Also, set AutoGenerateColumns to true. (Or explicitly specify columns)
Without seeing any code, I'd suggest the two most important points are:
setting the DataContext with myGrid.DataContext = myDS.Tables[0];
having your XAML DataGrid include the ItemsSource property:
<dg:DataGrid ItemsSource="{Binding Path=.}"

Categories