Xamarin - I can't load images in iPhone but can in Android and iPhone simulator - iphone

I am having trouble with images on the iPhone. They work fine on Android (both emulator and actual devices) and on the iPhone simulator. However, on an actual iPhone device, I can’t display images unless they are in the asset catalog. I started with a fresh project and it did display. Then, I added files (that were not used – as the only thing in my App.xaml.cs was a load of the page displaying the images). At some point, the images quit showing up so it appears to be a build error of some sort but I can’t figure it out. Android Emulator:
iPhone Simulator:
Actual iPhone:
So, for the iPhone, ffImageLoading can load a .svg from my local device but none of the .png files or remote urls. Xamarin.Image can’t load anything.
Any ideas? Is this some sort of build problem? My build settings are:
If I Enable the Mono Interpreter OR I leave out the mtouch options (all that works is Mono interpreter disable and mtouch options set), I get the dreaded “Could not AOT the assembly…” error.
I have tried different Architectures. I have tried different linking behavior. Not sure what else to try.
Any help or thoughts on work-arounds would be greatly appreciated!
Thanks!
Greg
Attached is the source but it's not much to look at.
Testpage2.xaml
<ContentPage.Resources>
<Style x:Key="MyImage" TargetType="Image">
<Setter Property="WidthRequest" Value="25" />
</Style>
</ContentPage.Resources>
<ContentPage.Content>
<ScrollView>
<StackLayout BackgroundColor="Wheat">
<Label Text="ffImageLoading local resource" TextColor="Red" />
<ffimageloadingsvg:SvgCachedImage Source="resource://ONEflight.BAJit.App.Images.Buttons.MyProfileButton.svg" Style="{StaticResource MyImage}" />
<Label Text="URL Image using ffImageLoading" TextColor="Red" />
<ffimageloading:CachedImage Source="https://ofpublicwebdata.blob.core.windows.net/of-public-data-aircraft-images/9ef83699-d8e8-44d9-ac94-2a26359aac9d.jpg" Style="{StaticResource MyImage}" />
<Label Text="URL Source in xaml using Xamarin.Image" TextColor="Red" />
<Image Source="https://ofpublicwebdata.blob.core.windows.net/of-public-data-aircraft-images/9ef83699-d8e8-44d9-ac94-2a26359aac9d.jpg" Style="{StaticResource MyImage}" />
<Label Text="URL Source as string in Code using Xamarin.Image" TextColor="Red" />
<Image Source="{Binding UrlStr}" Style="{StaticResource MyImage}" />
<Label Text="URL downloaded using MemStream in Code using Xamarin.Image" TextColor="Red" />
<Image Source="{Binding ImageDownloadedToMemStream}" Style="{StaticResource MyImage}" />
<Label Text="Local png using Xamarin.Image" TextColor="Red" />
<Image Source="{ex:ImageResource Images.Amenities.pets.png}" Style="{StaticResource MyImage}" />
</StackLayout>
</ScrollView>
</ContentPage.Content>
TestViewModel2.cs
public string UrlStr { get; set; }
public ImageSource ImageDownloadedToMemStream { get; set; }
public ImageSource Pets => Resources.PetsIcon;
public ImageSource URITest { get; set; }
public TestViewModel2()
{
string url = "https://ofpublicwebdata.blob.core.windows.net/of-public-data-aircraft-images/9ef83699-d8e8-44d9-ac94-2a26359aac9d.jpg";
try
{
UrlStr = url;
MemoryStream ms = new MemoryStream(new WebClient().DownloadData(url));
ImageDownloadedToMemStream = ImageSource.FromStream(() => ms);
URITest = ImageSource.FromUri(new Uri(url));
}
catch (Exception ex)
{
LogWriter.Log("Image Error: " + ex.Message);
}
}
App.xaml.cs
MainPage = new NavigationPage(new TestPage2(new TestViewModel2()));

Related

Child property of an ObservableProperty is not updating

Something isn't right with the XAML but it's not sticking out at me.
I've been working on the layout of one of my .net Maui XAML pages. I added a collectionView when I noticed that the top data was no longer showing. The other pages are working fine.
What's weird is that the data is there and while running the app in debug mode if I highlight, shift-delete, then paste it back in the bound data appears. I also noticed if I change the {Binding EditEvent.name} by removing the "name" from EditEvent then adding it back on, the view displays the data as well.
But if I leave and navigate back in the data won't show up until I repeat the above process. It's like the viewModel isn't updating the view when the data changes. But if I force the view to update by deleting and re-pasting it will show it.
Anyone have an idea what possibly could be the issue?
I've got 2 ObservableProperties in my ViewModel:
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Newtonsoft.Json;
using SharedModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyApp.ViewModels
{
public partial class EditEventViewModel : ObservableObject
{
#region XAML page Observables
[ObservableProperty]
attEventDx editEvent;
[ObservableProperty]
ObservableCollection<groupReturn> groupsItems;
#endregion
// pass object to edit into this view
public async void SetEditEvent(attEventDx incomingEvent)
{
editEvent = incomingEvent;
//await LoadGroupsAsync();
}
...
}
And this is the view:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Pages.EditEventPage"
Title="Edit Event"
xmlns:viewmodel="clr-namespace:MyApp.ViewModels"
xmlns:dm="clr-namespace:SharedModels;assembly=SharedModels"
x:DataType="viewmodel:EditEventViewModel"
NavigatedTo="ContentPage_NavigatedTo">
<VerticalStackLayout>
<Grid HorizontalOptions="Center" VerticalOptions="Start" Padding="0,40,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label Text="Event Name" VerticalOptions="Center" HorizontalOptions="Center" Grid.Column="0" Grid.Row="0"/>
<Entry Text="{Binding EditEvent.name}" WidthRequest="200" Grid.Column="1" Grid.Row="0"/>
<Label Text="Event Date" VerticalOptions="Center" HorizontalOptions="Center" Grid.Column="0" Grid.Row="1"/>
<Entry Text="{Binding EditEvent.happeningOn}" WidthRequest="200" Grid.Column="1" Grid.Row="1"/>
</Grid>
<Label Text="Selectable Groupings" VerticalOptions="Center" HorizontalOptions="Center" Padding="20"/>
<CollectionView ItemsSource="{Binding GroupsItems}" SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="dm:groupReturn">
<SwipeView>
<SwipeView.RightItems>
<SwipeItem Text="Delete" BackgroundColor="Red"/>
</SwipeView.RightItems>
<Grid Padding="0,5">
<Label Text="Groups"/>
<ScrollView>
<Frame>
<Frame.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:EditEventViewModel}}, Path=TapCommand}"
CommandParameter="{Binding .}" />
</Frame.GestureRecognizers>
<Label Text="{Binding groupName}" FontSize="20" FontAttributes="Bold"/>
</Frame>
</ScrollView>
</Grid>
</SwipeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
this is my xaml.cs for that page:
public partial class EditEventPage : ContentPage, IQueryAttributable
{
EditEventViewModel _vm;
attEventDx _editEvent;
public EditEventPage( EditEventViewModel vm)
{
InitializeComponent();
_vm = vm;
BindingContext = _vm;
}
public void ApplyQueryAttributes(IDictionary<string, object> query)
{
_editEvent = query["EditEvent"] as attEventDx;
}
private void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{
_vm.SetEditEvent(_editEvent);
}
}
attEventDx for reference (sits in another shared project between Azure Functions and the mobile app):
namespace SharedModels
{
public class attEventDx
{
public Guid? publicId { get; set; }
public int? createdBy { get; set; }
public string name { get; set; }
public DateTime dateCreated { get; set; }
public DateTime? happeningOn { get; set; }
}
}
As I referred to this is the page that IS working:
xaml.cs:
public partial class EventPage : ContentPage
{
EventViewModel _vm;
public EventPage(EventViewModel vm)
{
InitializeComponent();
_vm = vm;
BindingContext= _vm;
}
private async void ContentPage_NavigatedTo(object sender, NavigatedToEventArgs e)
{
await _vm.LoadEventData();
}
private void ImageButton_Clicked(object sender, EventArgs e)
{
}
}
ViewModel:
public partial class EventViewModel : ObservableObject
{
#region XAML page Observables
[ObservableProperty]
ObservableCollection<attEventDx> eventItems;
[ObservableProperty]
attEventDx selectedEvent;
[ObservableProperty]
string text;
#endregion
public EventViewModel()
{
//EventItems = new ObservableCollection<attEventDx>();
}
[RelayCommand]
public async Task LoadEventData()
{
MyApp.globals.SetHttpClient();
try
{
var response = await MyApp.globals.httpClient.GetAsync(MyApp.globals.APIURL + "getEvents");
var allEvents = response.Content.ReadAsStringAsync().Result;
if (allEvents != null)
{
List<attEventDx> listOfEvents = JsonConvert.DeserializeObject<List<attEventDx>>(allEvents);
if (listOfEvents != null)
{
EventItems = new ObservableCollection<attEventDx>(listOfEvents);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\r\b" + ex.StackTrace);
}
}
[RelayCommand]
async Task Add()
{
await Shell.Current.GoToAsync($"{nameof(AddEventPage)}");
}
[RelayCommand]
async Task Tap(attEventDx sender)
{
selectedEvent = sender;
var navigationParameter = new Dictionary<string, object>
{
["EditEvent"] = selectedEvent
};
await Shell.Current.GoToAsync($"{nameof(EditEventPage)}", navigationParameter);
}
[RelayCommand]
async Task Refresh()
{
await LoadEventData();
}
}
And the view of the working page:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.EventPage"
Title="Events"
xmlns:viewmodel="clr-namespace:MyApp.ViewModels"
xmlns:dm="clr-namespace:SharedModels;assembly=SharedModels"
x:DataType="viewmodel:EventViewModel"
NavigatedTo="ContentPage_NavigatedTo">
<Grid RowDefinitions="100, Auto, 30, *"
ColumnDefinitions=".50*, .25*, .25*"
Padding="10">
<Image Grid.ColumnSpan="3"
Source="logo.png"
BackgroundColor="Transparent"/>
<ImageButton Source="plus.png" Grid.Row="0" Grid.Column="2" Scale=".7" Command="{Binding AddCommand}"></ImageButton>
<Label Text="New Event" Grid.Column="2" Grid.Row="0" HorizontalOptions="Center" VerticalOptions="End"></Label>
<!--<Entry Placeholder="Enter Text" Grid.Row="1" Text="{Binding Text}" />-->
<!--<Button Text="Search" Grid.Row="1" Grid.Column="1" />-->
<!--<Button Text="Add" Grid.Row="1" Grid.Column="2" Command="{Binding AddCommand}"/>-->
<Label Text="Upcoming Events" FontSize="22" Grid.Row="2"/>
<!--<Button Text="Refresh" Grid.Row="2" Grid.Column="2" Command="{Binding RefreshCommand}"/>-->
<CollectionView Grid.Row="3" Grid.ColumnSpan="3" ItemsSource="{Binding EventItems}" SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="dm:attEventDx">
<SwipeView>
<SwipeView.RightItems>
<SwipeItem Text="Delete" BackgroundColor="Red"/>
</SwipeView.RightItems>
<Grid Padding="0,5">
<Label Text="Event"/>
<ScrollView>
<Frame>
<Frame.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:EventViewModel}}, Path=TapCommand}"
CommandParameter="{Binding .}" />
</Frame.GestureRecognizers>
<Label Text="{Binding name}" FontSize="20" FontAttributes="Bold"/>
</Frame>
</ScrollView>
<Label Text="{Binding happeningOn}" HorizontalOptions="End" VerticalOptions="Center" Padding="0,0,5,0"></Label>
</Grid>
</SwipeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</Grid>
Well, what ToolmakerSteve told me kind of worked, the items were initially displaying but not updating.
I then decided to build out another page in the app and do some experimenting along the way and figured out the issue.
When I created the new page by hand, I still had this issue and was doubting my sanity. I then partially copied in the page that was working and it worked! In comparing the two pages closely, I finally discovered what the problem was.
I was right, the CommunityToolkit's [ObservableProprerty] DOES work for all child items in an object; this is why I selected using this library from the start. I wasn't going crazy... (At least not on this)
This particular app was started a few months ago but then I got pulled into another project in another platform for a few months so what I had learned was partially forgotten when I picked it back up recently.
When you define a [ObservableProperty] like this:
[ObservableProperty]
myObject usedVariable;
The "usedVariable" will contain the data, but not the framework for INotifyPropertyChanged. CommunityToolkit builds out the framework on "UsedVariable".
While this code is "legal" in the ViewModel:
usedVariable = new myObject();
It will assign the data, but not the notification framework.
Instead it needs to be:
UsedVariable = new myObject();
Once the variable is defined with lowercase, you will never reference the variable that way again (as far as I can tell anyway). Instead, you will use the uppercase "UsedVariable".
When I referenced the lowercase version of the variable, I didn't see the data on the app page when it started. However, if I had the page open and I removed the XAML code for that control and pasted it back in, the data did show.
It's always something simple that causes the most grief...

Add Control programmatically, UI is not updating

I am just playing arround with .Net MAUI.
I want to retrieve information from a Rest service and based on the result I want to add Buttons programmatically to a VerticalStackLayout.
When I debug the solution the buttons are added to the VerticalStackLayout but the UI is not updated.
Here the code Snippet
var btn = new Button();
btn.Text = "Button " + count + " added";
btn.Clicked += OnCounterClicked;
btn.HorizontalOptions = LayoutOptions.Center;
VLayout.Add(btn);
Here the XAML
<ScrollView>
<VerticalStackLayout x:Name="VLayout"
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />
<Entry x:Name="entry"
Placeholder="Enter text"
TextChanged="OnTextChanged"
Completed="OnTextCompleted" />
<Button
x:Name="KommenBtn"
Text="Kommen"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
<Button
x:Name="GehenBtn"
Text="Gehen"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ScrollView>
Thanks in advance for your hints & help!
BW
Try to update UI on main thread , you can wrap your code into Application.Current.Dispatcher.Dispatch .
Sample code
Application.Current.Dispatcher.Dispatch(() =>
{
var btn = new Button();
btn.Text = "Button " + count + " added";
btn.Clicked += OnCounterClicked;
btn.HorizontalOptions = LayoutOptions.Center;
VLayout.Add(btn);
});
To update UI after a change that affects the hierarchy (or positions) of controls:
(VLayout as IView).InvalidateArrange();
NOTE: This is roughly equivalent to Xamarin.Forms layout.ForceLayout();
If not already in code running on UI MainThread, wrap it in Dispatch:
Dispatcher.Dispatch(() =>
(VLayout as IView).InvalidateArrange());

Keyboard not hiding after push done or leave Entry

I am facing a problem with hiding the Keyboard after I am done using it or leave the Entry and touching the screen somewhere.
In Xamarin Forms, it is working normally, the Keyboard is hiding but in Maui it is not?
<CheckBox
x:Name="Cbbb1"
Grid.Row="1"
Grid.Column="0"/>
<Entry
x:Name="Ebb1"
Grid.Row="2"
Grid.Column="2"
Keyboard="Numeric" />
Remove Keyboard="Numeric" is not helping.
I am using VisualStudio 2022 preview Version 17.1.0 Preview 3.0.
I also tried this:
xmlns:local="clr-namespace:KeyboardhideMaui"
And this:
<Entry.Triggers>
<DataTrigger TargetType="Entry" >
<Trigger.EnterActions>
<local:FocusTriggerAction Focused="True" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<local:FocusTriggerAction Focused="False" />
</Trigger.ExitActions>
</DataTrigger>
</Entry.Triggers>
<CheckBox
x:Name="Cbbb1"
Grid.Row="1"
Grid.Column="0" />
<Entry
x:Name="Ebb1"
Grid.Row="2"
Grid.Column="2"
Keyboard="Numeric" />
Class
public class FocusTriggerAction : TriggerAction<Entry>
{
public bool Focused { get; set; }
protected override async void Invoke(Entry entry)
{
await Task.Delay(1000);
if (Focused)
{
entry.Focus();
}
else
{
entry.UnFocus();
}
}
}
I'm getting below error on entry.UnFocus();:
'Entry' does not contain a definition for 'UnFocus' and no accessible extension method
'UnFocus' accepting a first argument of type 'Entry' could be found (are you missing a using directive or an assembly reference?)
try this please :
Add this in your xaml page ( page resources )
<Style TargetType="Entry">
<Style.Triggers>
<EventTrigger Event="Unfocused">
<local:UnFocusTriggerAction />
</EventTrigger>
</Style.Triggers>
</Style>
then add UnFocusTriggerAction in your project
public class UnFocusTriggerAction : TriggerAction<Entry>
{
protected override void Invoke(Entry entry)
{
entry.Unfocus();
}
}

Implement data validation in entity framework code first

I am using entity framework 6, .Net framework 4 and code first.
I am able to get the validation errors by using GetValidationResult method. But I was not able to show the validation message like the one given in the below image. How to achieve this?
My Code:
<Label Content="Name" />
<Grid Grid.Row="0" Grid.Column="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox x:Name="txtName"
Width="200"
Margin="8,0,0,0"
MaxLength="150"
Text="{Binding Path=dfc_Name,
ValidatesOnDataErrors=True}" />
</Grid>
<Label Grid.Row="4"
Grid.Column="0"
Content="Description" />
<TextBox x:Name="txtDescription"
Grid.Row="4"
Grid.Column="2"
Width="300"
Height="80"
Margin="8,0,0,0"
HorizontalAlignment="Left"
VerticalContentAlignment="Top"
AcceptsReturn="True"
Text="{Binding Path=dfc_Description,
ValidatesOnDataErrors=True}"
TextWrapping="WrapWithOverflow" />
</Grid>
Code Behind:
private readonly Item OItem = new Item();
public ItemView()
{
InitializeComponent();
this.DataContext = OItem;
if (context.Entry(OItem).GetValidationResult().IsValid)
{
}
else
{
}
}
You should decorate your code first POCO classes.
This can look like:
[StringLength(25, ErrorMessage = "Blogger Name must be less than 25 characters", MinimumLength = 1)]
[Required]
public string BloggerName{ get; set; }
You can then get the specific errors using an extension method like this:
public static List<System.ComponentModel.DataAnnotations.ValidationResult> GetModelErrors(this object entity)
{
var errorList= new List<System.ComponentModel.DataAnnotations.ValidationResult>();
System.ComponentModel.DataAnnotations.Validator.TryValidateObject(entity, new ValidationContext(entity,null,null), errorList);
return errorList.Count != 0 ? errorList: null;
}
You could then use the list as a property to populate a validation template in your view. In your example this could occur on the 'Save' click event.

SilverLight 4.0 C# - DomainDataSource DataGrid with CheckBox Column (UI only - not a data field) to allow user to select multiple records/rows

New to SilverLight and to posting here. Please have mercy and be specific :)
Using RIA services with DomainDataSource and DataGrid control to display data rows from SQL server query
Goal: Have checkbox column (UI only - not a data field) to allow user to select multiple records/rows
BackGround:
1) Created new SilverLight 4, C# solution with RIA services
2) in ProjectName.Web
Created Entity Framework (EF) model referencing SQL server table/view (built solution).
Created Domain Sevice using EF model (built solution).
3) in SilverLightProjectName
From Data Sources window, dragged table onto a design surface to create DomainDataSource and DataGrid (this works great to bind DataGrid to data source)
4) in MainPage.XAML added checkbox column
What's Happening: checkboxes are selected/checked by user, scroll down, scroll back up, all checkboxes reset and ONLY Datagrid.SelectedItem is still checked. I have read this behavior is 'by design' due to paging.
<sdk:DataGrid RowStyle="{StaticResource newDataGridStyle}" AutoGenerateColumns="False" ItemsSource="{Binding ElementName=ddsPagerApp, Path=Data}" Name="vwPagerAppDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" MouseLeftButtonDown="vwPagerAppDataGrid_MouseLeftButtonDown" VerticalGridLinesBrush="#FFB9B9B9" FontSize="10" Grid.Row="3" SelectionChanged="vwPagerAppDataGrid_SelectionChanged" KeyDown="vwPagerAppDataGrid_KeyDown" MouseLeftButtonUp="vwPagerAppDataGrid_MouseLeftButtonUp" MouseRightButtonUp="vwPagerAppDataGrid_MouseRightButtonUp" DataContext="{Binding}" SelectionMode="Single" IsEnabled="True" IsReadOnly="False" TabIndex="2" Grid.Column="1" Margin="0,10,9,9">
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn IsReadOnly="False">
<sdk:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<CheckBox Name="ChkSelected" IsThreeState="False" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" Unchecked="IndividualCheckBox_Unchecked" Checked="IndividualCheckBox_Checked" Width="Auto" Height="Auto" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTextColumn x:Name="fullNameColumn" Binding="{Binding Path=FullName}" Header="Full Name" IsReadOnly="True" />
<sdk:DataGridTextColumn x:Name="departmentColumn" Binding="{Binding Path=department}" Header="Department" IsReadOnly="True" />
<sdk:DataGridTextColumn x:Name="pager_number_displayColumn" Binding="{Binding Path=pager_number_display}" Header="Pager Number" IsReadOnly="True" />
<sdk:DataGridTextColumn x:Name="PageTo" Binding="{Binding Path=PageTo}" Header="Page To" IsReadOnly="True" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my:vwPagerApp, CreateList=true}" Height="0" LoadedData="ddsPagerApp_LoadedData" Name="ddsPagerApp" QueryName="GetVwPagerAppsQuery" Width="0" Margin="10,0,25,45" Background="#FF7D0000" Foreground="#FF7D0000" Visibility="Visible">
<riaControls:DomainDataSource.DomainContext>
<my:NotifyDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
Attempt 1:
in EFModel.edmx, added Boolean Scalar Property 'IsChecked'
in DomainService.metadata.cs, added public bool IsChecked { get; set; }
in MainPage.XAML. added (above) IsChecked="{Binding Path=IsChecked, Mode=TwoWay}"
Getting error: Error 11009: Property ' ' is not mapped
UPDATE: Reversed Attempt 1:
Attempt 2:
Researching possibility of defining a partial class for the entity, wiring to DataGrid, and using that to track CheckBox values. Any advice on if this will work/how to?
Trying my best to absorb this. Please enlighten me...and thank you in advance :)
This is what I implemented and it worked beautifully. I hope it helps someone else in the future :)
1) SilverLight Project C#: Extend entity class using partial class (in separate file, but within same namespace – compiles into 1 class but keeps generated code separate)
namespace Pager.Web
{
public partial class pager_grp
{
bool _IsChecked = false;
public bool IsChecked
{
get
{return this._IsChecked;}
set
{this._IsChecked = !IsChecked;}
}
}
}
2) SilverLight Project GUI: Create Column in DataGrid of type DataGridTemplateColumn named chkSelected
3) SilverLight Project XAML: use template and bind to new property declared in partial class
<sdk:DataGridTemplateColumn IsReadOnly="False">
<sdk:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<CheckBox Name="ChkSelected" IsThreeState="False" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" Unchecked="IndividualCheckBox_Unchecked" Checked="IndividualCheckBox_Checked" Width="Auto" Height="Auto" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>