I have a list of contacts, I want to display the alphabet and grey out the letters that do not have corresponding contacts.
in my Model I have:
public class ContactInitial
{
public string Initial { get; set; }
}
This is derived from the database.
In my View I have the following
<StackPanel Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left" Width="17">
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">A</Button >
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">B</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">C</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">D</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">E</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">F</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">G</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">H</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">I</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">J</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">K</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">L</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">M</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">N</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">O</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">P</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">Q</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">R</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">S</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">T</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">U</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">V</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">W</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">X</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">Y</Button>
<Button Height="17" Background="#FFFBF5A6" BorderBrush="{x:Null}">Z</Button>
</StackPanel>
I am struggling to work out how I bind the foreground colour to be grey if the letter is not in the ContactInitial and black if it is.
Thanks for your help
I would implement it with a style, which you could put to the resources of your window, or your container control, for the style would be applied to all buttons in window/control.
In this style you can put a trigger, which will triggered, if the condition is true. The condition I would check in a multi value converter, which should be used in the binding of you view model property and Content property of the button.
This one should work:
<Window.DataContext>
<local:ViewModel ></local:ViewModel>
</Window.DataContext>
<Window.Resources>
<local:ContainsStringConverter x:Key="strContConv"/>
<Style TargetType="Button">
<Setter Property="Foreground" Value="Gray"/>
<Style.Triggers>
<DataTrigger Value="true">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource strContConv}">
<Binding Path="InitialString"/>
<Binding RelativeSource="{RelativeSource Self}" Path="Content"/>
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Foreground" Value="Black"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
public class ContainsStringConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values==null || values.Length<2 || !values.All(v=>v is string))
{
return false;
}
var retVal = true;
var initalStr = values[0] as string;
for (int i = 1; i < values.Length; i++)
{
retVal &= initalStr.Contains(values[i] as string);
}
return retVal;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class ViewModel : ViewModelBase
{
public ViewModel()
{
_initialString = Model.Initial;
}
public ContactInitial Model { get; set; } = new ContactInitial { Initial = "AC" };
public string InitialString
{
get
{
return _initialString;
}
set
{
if (value != _initialString)
{
_initialString = value;
Model.Initial = _initialString;
NotifyPropertyChanged(nameof(InitialString));
}
}
}
private string _initialString;
}
Related
Preparing a bootstrap application to install some msi packages. Have option to choose the packages to install. But the variable value is not changing as per the user selection.
This is how I use variable in my Bundle.wxs file
<Variable Name="spectrumDb" Persisted="yes" bal:Overridable="yes" Value="1" />
<Variable Name="spectrumGateway" Persisted="yes" bal:Overridable="yes" Value="1" />
<Variable Name="spectrumServiceManager" Persisted="yes" bal:Overridable="yes" Value="1" />
<Variable Name="spectrumIISparts" Persisted="yes" bal:Overridable="yes" Value="1" />
<Variable Name="spectrumConnecter" Persisted="yes" bal:Overridable="yes" Value="1" />
I have some checkboxes in rtf theme for the user to select components to install
<Page Name="Options">
<Text X="11" Y="65" Width="-11" Height="30" FontId="2" DisablePrefix="yes">Select components</Text>
<Checkbox Name="spectrumDb" X="40" Y="120" Width="200" Height="17" TabStop="yes" FontId="3" HideWhenDisabled="no" >spectrumDb</Checkbox>
<Checkbox Name="spectrumGateway" X="40" Y="140" Width="200" Height="17" TabStop="yes" FontId="3" HideWhenDisabled="no">spectrumGateway</Checkbox>
<Checkbox Name="spectrumServiceManager" X="40" Y="160" Width="200" Height="17" TabStop="yes" FontId="3" HideWhenDisabled="no" >spectrumServiceManager</Checkbox>
<Checkbox Name="spectrumIISparts" X="40" Y="180" Width="200" Height="17" TabStop="yes" FontId="3" HideWhenDisabled="no" >spectrumIISparts</Checkbox>
<Checkbox Name="spectrumConnecter" X="40" Y="200" Width="200" Height="17" TabStop="yes" FontId="3" HideWhenDisabled="no" >spectrumConnecter</Checkbox>
</Page>
The installer install irrespective of the checkbox value. This is the part of logfile where I find that
[0404:0B44][2018-05-28T08:43:07]i000: Running detect complete custom action
[0404:0B44][2018-05-28T08:43:07]i199: Detect complete, result: 0x0
[0404:178C][2018-05-28T08:43:09]i000: Setting numeric variable 'EulaAcceptCheckbox' to value 1
[0404:178C][2018-05-28T08:43:20]i000: Setting numeric variable 'spectrumDb' to value 1
[0404:178C][2018-05-28T08:43:20]i000: Setting numeric variable 'spectrumGateway' to value 1
[0404:178C][2018-05-28T08:43:20]i000: Setting numeric variable 'spectrumServiceManager' to value 1
[0404:178C][2018-05-28T08:43:20]i000: Setting numeric variable 'spectrumIISparts' to value 1
[0404:178C][2018-05-28T08:43:20]i000: Setting numeric variable 'spectrumConnecter' to value 1
I use wix 3.11 to make this project.
ide is visual studio 2010.
bootstrap application type ref WixExtendedBootstrapperApplication.RtfLicense
The bootstrapper will set the variable when it runs this function:
void SavePageSettings(
__in WIXSTDBA_PAGE page
)
{
THEME_PAGE* pPage = NULL;
pPage = ThemeGetPage(m_pTheme, m_rgdwPageIds[page]);
if (pPage)
{
for (DWORD i = 0; i < pPage->cControlIndices; ++i)
{
// Loop through all the checkbox controls (or buttons with BS_AUTORADIOBUTTON) with names and set a Burn variable with that name to true or false.
THEME_CONTROL* pControl = m_pTheme->rgControls + pPage->rgdwControlIndices[i];
if ((THEME_CONTROL_TYPE_CHECKBOX == pControl->type) ||
(THEME_CONTROL_TYPE_BUTTON == pControl->type && (BS_AUTORADIOBUTTON == (BS_AUTORADIOBUTTON & pControl->dwStyle)) &&
pControl->sczName && *pControl->sczName))
{
BOOL bChecked = ThemeIsControlChecked(m_pTheme, pControl->wId);
m_pEngine->SetVariableNumeric(pControl->sczName, bChecked ? 1 : 0);
}
// Loop through all the editbox controls with names and set a Burn variable with that name to the contents.
if (THEME_CONTROL_TYPE_EDITBOX == pControl->type && pControl->sczName && *pControl->sczName && WIXSTDBA_CONTROL_FOLDER_EDITBOX != pControl->wId)
{
LPWSTR sczValue = NULL;
ThemeGetTextControl(m_pTheme, pControl->wId, &sczValue);
m_pEngine->SetVariableString(pControl->sczName, sczValue);
}
}
}
}
The SetVariableNumeric function won't log anything for an already existing variable.
You can verify your variables are being set by running your bootstrapper, unchecking a few check boxes, going to the next page, and then cancelling your bootstrapper.
When you close the bootstrapper it logs all variables and their values. In the logs after you close the bootstrapper, you should see that the variables corresponding to the checkboxes you unchecked should now have a value of 0.
I am trying to write a directive to change colour of a button on "Touchup" and "TouchDown". But when I attach this directive the (tap) event in the component is not getting called. This happens only in iOS. Is there any workarounds for this. Below is my directive and component.
import { Directive, HostBinding, HostListener, ElementRef, Renderer2 } from '#angular/core';
#Directive({
selector: '[btnTch]'
})
export class btnTchDirective {
constructor(private el: ElementRef, private renderer: Renderer2) { }
#HostListener('touch', ['$event'])
toggleColor(event){
if(event.action == "down"){
this.renderer.addClass(this.el.nativeElement, 'pressed');
// this.renderer.setStyle(this.el.nativeElement, 'backgroundColor', "blue");
}else{
this.renderer.removeClass(this.el.nativeElement, 'pressed');
}
}
}
<ActionBar title="Login" actionBarHidden="false"></ActionBar>
<GridLayout columns="*" rows="auto, *, 130" width="100%" height="100%" class="login_bg">
<GridLayout columns="*" rows="*" verticalAlignment="center" horizontalAlignment="center">
<Label text="" style="border-radius:62; width:125; height:125; padding:0;margin-top:100; margin-bottom:10; background-color:white;opacity:0.1"></Label>
<Label text="" style="border-radius:50; width:100; height:100; padding:0;margin-top:100; margin-bottom:10; background-color:white;opacity:0.1"></Label>
</GridLayout>
<StackLayout col="0" row="1" verticalAlignment="center" style="width:80%">
<Label text="Enter Mobile Number"></Label>
<TextField hint="Enter Mobile Number" [(ngModel)]="userNum" style="border-bottom-width:1; border-style:solid; border-color: red; padding:5 0"></TextField>
<Label *ngIf="!genErrs == '' || null || undefined" text="{{genErrs}}"></Label>
</StackLayout>
<StackLayout col="0" row="2">
<Button text="SIGN IN" btnTch (tap)="Auth_for_OTP()"></Button>
<Label marginTop="15" horizontalAlignment="center" text="REQUEST FOR ACCESS" [nsRouterLink]="['/signup']" ></Label>
</StackLayout>
</GridLayout>
I'm get an issue using the Template 10 Hamburger Template and Zxing.mobile.net library
"Template10": "1.1.12",
"ZXing.Net.Mobile": "2.1.46"
if I add the following code to the Mainpage and Viewmodel, the scanner works correctly and binds the value back to the TextBox but if I add the same code to the details page the returned code wont bind.I'm doing anything wrong.
Mainpage.xaml
<Page x:Class="WindowsApp3.Views.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Behaviors="using:Template10.Behaviors"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:controls="using:Template10.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:WindowsApp3.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:WindowsApp3.ViewModels"
mc:Ignorable="d">
<Page.DataContext>
<vm:MainPageViewModel x:Name="ViewModel" />
</Page.DataContext>
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="AdaptiveVisualStateGroup">
<VisualState x:Name="VisualStateNarrow">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource NarrowMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!-- TODO: change properties for narrow view -->
<Setter Target="stateTextBox.Text" Value="Narrow Visual State" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateNormal">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource NormalMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!-- TODO: change properties for normal view -->
<Setter Target="stateTextBox.Text" Value="Normal Visual State" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateWide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource WideMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!-- TODO: change properties for wide view -->
<Setter Target="stateTextBox.Text" Value="Wide Visual State" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<controls:PageHeader x:Name="pageHeader"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignTopWithPanel="True"
Text="Main Page">
<!-- secondary commands -->
<controls:PageHeader.SecondaryCommands>
<AppBarButton Click="{x:Bind ViewModel.GotoSettings}" Label="Settings" />
<AppBarButton Click="{x:Bind ViewModel.GotoPrivacy}" Label="Privacy" />
<AppBarButton Click="{x:Bind ViewModel.GotoAbout}" Label="About" />
</controls:PageHeader.SecondaryCommands>
</controls:PageHeader>
<RelativePanel EntranceNavigationTransitionInfo.IsTargetElement="True"
RelativePanel.AlignBottomWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.Below="pageHeader">
<controls:Resizer x:Name="parameterResizer" Margin="16,16,16,0">
<TextBox MinWidth="150"
MinHeight="62"
Header="Parameter to pass"
Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap">
<Interactivity:Interaction.Behaviors>
<!-- enable submit on enter key -->
<Behaviors:KeyBehavior Key="Enter">
<Core:CallMethodAction MethodName="GotoDetailsPage" TargetObject="{Binding}" />
</Behaviors:KeyBehavior>
<!-- focus on textbox when page loads -->
<Core:EventTriggerBehavior>
<Behaviors:FocusAction />
</Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBox>
</controls:Resizer>
<Button x:Name="submitButton"
Click="{x:Bind ViewModel.GotoDetailsPage}"
Content="Submit"
RelativePanel.AlignBottomWith="parameterResizer"
RelativePanel.RightOf="parameterResizer" />
<TextBlock x:Name="stateTextBox"
Margin="16,16,0,0"
RelativePanel.AlignLeftWith="parameterResizer"
RelativePanel.Below="parameterResizer"
Text="Current Visual State" />
<!-- content -->
<!-- content -->
<Button x:Name="loadButton"
HorizontalAlignment="Center"
Width="180"
Height="50"
RelativePanel.Below="stateTextBox"
Click="{x:Bind ViewModel.QRCodeCick}">
<StackPanel Orientation="Horizontal">
<SymbolIcon Width="48"
VerticalAlignment="Center"
Height="48"
Symbol="Camera" />
<TextBlock Margin="12,0,0,0"
VerticalAlignment="Center"
Text="Read QR Code" />
</StackPanel>
</Button>
<TextBox x:Name="QRTextBox"
PlaceholderText="Enter Code"
Text="{x:Bind ViewModel.QRText,Mode=TwoWay}"
RelativePanel.Below="loadButton"
Margin="0,0,0,12"/>
</RelativePanel>
</RelativePanel>
</Page>
MainPage.xaml.cs
using System;
using WindowsApp3.ViewModels;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using System.Collections.ObjectModel;
namespace WindowsApp3.Views
{
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
NavigationCacheMode = Windows.UI.Xaml.Navigation.NavigationCacheMode.Enabled;
}
}
}
MagePageViewModel.cs
using Template10.Mvvm;
using System.Collections.Generic;
using System;
using System.Linq;
using System.Threading.Tasks;
using Template10.Services.NavigationService;
using Windows.UI.Xaml.Navigation;
using ZXing.Mobile;
namespace WindowsApp3.ViewModels
{
public class MainPageViewModel : ViewModelBase
{
MobileBarcodeScanner scanner;
public MainPageViewModel()
{
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
Value = "Designtime value";
}
//Create a new instance of our scanner
scanner = new MobileBarcodeScanner();
// this.Dispatcher
// scanner.Dispatcher = this.Dispatcher;
}
string _Value = "Gas";
public string Value { get { return _Value; } set { Set(ref _Value, value); } }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary<string, object> suspensionState)
{
if (suspensionState.Any())
{
Value = suspensionState[nameof(Value)]?.ToString();
}
await Task.CompletedTask;
}
public override async Task OnNavigatedFromAsync(IDictionary<string, object> suspensionState, bool suspending)
{
if (suspending)
{
suspensionState[nameof(Value)] = Value;
}
await Task.CompletedTask;
}
public override async Task OnNavigatingFromAsync(NavigatingEventArgs args)
{
args.Cancel = false;
await Task.CompletedTask;
}
public void GotoDetailsPage() =>
NavigationService.Navigate(typeof(Views.DetailPage), Value);
public void GotoSettings() =>
NavigationService.Navigate(typeof(Views.SettingsPage), 0);
public void GotoPrivacy() =>
NavigationService.Navigate(typeof(Views.SettingsPage), 1);
public void GotoAbout() =>
NavigationService.Navigate(typeof(Views.SettingsPage), 2);
public async void QRCodeCick()
{
scanner.UseCustomOverlay = false;
scanner.TopText = "Hold camera up to barcode";
scanner.BottomText = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel";
//Start scanning
var result = await scanner.Scan();
if (result != null)
_QRText = result.Text;
}
string _QRText;
public string QRText { get { return _QRText; } set { Set(ref _QRText, value); } }
}
}
Details.xaml
<Page x:Class="WindowsApp3.Views.DetailPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Behaviors="using:Template10.Behaviors"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:controls="using:Template10.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:WindowsApp3.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:WindowsApp3.ViewModels"
x:Name="ThisPage"
mc:Ignorable="d">
<Page.DataContext>
<vm:DetailPageViewModel x:Name="ViewModel" />
</Page.DataContext>
<RelativePanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="AdaptiveVisualStateGroup">
<VisualState x:Name="VisualStateNarrow">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource NarrowMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!-- TODO: change properties for narrow view -->
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateNormal">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource NormalMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!-- TODO: change properties for normal view -->
</VisualState.Setters>
</VisualState>
<VisualState x:Name="VisualStateWide">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="{StaticResource WideMinWidth}" />
</VisualState.StateTriggers>
<VisualState.Setters>
<!-- TODO: change properties for wide view -->
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<!-- header -->
<controls:PageHeader x:Name="pageHeader"
Frame="{x:Bind Frame}"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignTopWithPanel="True"
Text="Detail Page" />
<!-- content -->
<ScrollViewer EntranceNavigationTransitionInfo.IsTargetElement="True"
Padding="12,8,0,0"
RelativePanel.AlignBottomWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.Below="pageHeader"
VerticalScrollBarVisibility="Auto">
<StackPanel>
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="You passed:" />
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="{x:Bind ViewModel.Value, Mode=OneWay, FallbackValue=DesigntimeValue}" />
<Button x:Name="loadButton"
HorizontalAlignment="Center"
Width="180"
Height="50"
Click="{x:Bind ViewModel.QRCodeCick}">
<StackPanel Orientation="Horizontal">
<SymbolIcon Width="48"
VerticalAlignment="Center"
Height="48"
Symbol="Camera" />
<TextBlock Margin="12,0,0,0"
VerticalAlignment="Center"
Text="Read QR Code" />
</StackPanel>
</Button>
<TextBox x:Name="QRTextBox"
PlaceholderText="Enter Code"
Text="{x:Bind ViewModel.QRText,Mode=TwoWay}"
Margin="0,0,0,12"/>
</StackPanel>
</ScrollViewer>
</RelativePanel>
</Page>
DesignPage.xaml.cs
using WindowsApp3.ViewModels;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Controls;
namespace WindowsApp3.Views
{
public sealed partial class DetailPage : Page
{
public DetailPage()
{
InitializeComponent();
NavigationCacheMode = NavigationCacheMode.Disabled;
}
}
}
DesignViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Template10.Common;
using Template10.Mvvm;
using Template10.Services.NavigationService;
using Windows.UI.Xaml.Navigation;
using ZXing.Mobile;
namespace WindowsApp3.ViewModels
{
public class DetailPageViewModel : ViewModelBase
{
MobileBarcodeScanner scanner;
public DetailPageViewModel()
{
if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
Value = "Designtime value";
}
//Create a new instance of our scanner
scanner = new MobileBarcodeScanner();
// this.Dispatcher
// scanner.Dispatcher = this.Dispatcher;
}
private string _Value = "Default";
public string Value { get { return _Value; } set { Set(ref _Value, value); } }
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary<string, object> suspensionState)
{
Value = (suspensionState.ContainsKey(nameof(Value))) ? suspensionState[nameof(Value)]?.ToString() : parameter?.ToString();
await Task.CompletedTask;
}
public override async Task OnNavigatedFromAsync(IDictionary<string, object> suspensionState, bool suspending)
{
if (suspending)
{
suspensionState[nameof(Value)] = Value;
}
await Task.CompletedTask;
}
public override async Task OnNavigatingFromAsync(NavigatingEventArgs args)
{
args.Cancel = false;
await Task.CompletedTask;
}
public async void QRCodeCick()
{
scanner.UseCustomOverlay = false;
scanner.TopText = "Hold camera up to barcode";
scanner.BottomText = "Camera will automatically scan barcode\r\n\r\nPress the 'Back' button to Cancel";
//Start scanning
var result = await scanner.Scan();
if (result != null)
_QRText = result.Text;
}
string _QRText;
public string QRText { get { return _QRText; } set { Set(ref _QRText, value); } }
}
}
I see two issues with your code:
1.) The _QRText = result.Text does not fire the PropertyChange for the binding.
2.) The main difference is in the pages' NavigationCacheMode property. You are using NavigationCacheMode.Enabled on MainPage and NavigationCacheMode.Disabled for DesignPage.
In the background the ZXing do a page navigation then a back navigation, so when it navigate back to the MainPage it uses the cached version so the ViewModel is cached too.
But in the DesignPage the caching is disabled so the back navigation creates a new page and view model instance so the following code is called in the old view model and not in the new one.
//Start scanning
var result = await scanner.Scan();
if (result != null)
_QRText = result.Text;
So you need to set the NavigationCacheMode property of the page to NavigationCacheMode.Required where you start the QR Code scanning.
I am using MVVM framework. My question is that i am binding PagedCollectionView to radgridview and using raddatapager i want to do paging. As i am new to this can anybody tell me where i am going wrong. Also there is one problem while fetching record this works fine for 800 records but it didn't work for records above 1000(web service code is attached).
In Web service i am using this function to get list:
public List<GetStudents> GetStudentsListForUpdate(int schoolId, int academicYearId)
{
return new DbHelper().Find(StudentAdmissionCommands.GetStudentsListForUpdate(schoolId, academicYearId), new GenericObjectBuilder<GetStudents>());
}
![It works first time when page is loaded as snapshot is attached][1]
In ViewModel I defined Pagedcollection view like this:
PagedCollectionView pcv;
public PagedCollectionView Pcv
{
get { return pcv; }
set { pcv = value; OnPropertyChanged("Pcv"); }
}
//This function written to get student's list
public void GetStud()
{
Studlist.Clear();
RootVisualHelper.SetBusy(true);
StudentAdmissionServiceClient client = new StudentAdmissionServiceClient();
client.GetStudentsListForUpdateCompleted += (Cs, Ea) =>
{
if (Ea.Error == null)
{
RootVisualHelper.SetBusy(false);
if (Ea.Result.ToList().Count == 0)
{
EmptyMessageVisibility = "Visible";
}
else
{
EmptyMessageVisibility = "Collapsed";
foreach (var item in Ea.Result)
{
Studlist.Add(item);
}
Pcv = new PagedCollectionView(Studlist);
Pcv.GroupDescriptions.Clear();
Pcv.GroupDescriptions.Add(new PropertyGroupDescription("AllocatedClass"));
}
}
};
client.GetStudentsListForUpdateAsync(SchoolIdLog, AcademicYearId);
}
In Xaml, RadGridView binding:
<telerik:RadGridView ItemsSource="{Binding Pcv}" SelectedItem="{Binding SelectedStudentList,Mode=TwoWay}"
telerik:StyleManager.Theme="{Binding Theme,Mode=TwoWay}"
helpers:CustomFilterBehavior.TextBox="{Binding ElementName=textBoxFilterValue}"
ShowColumnFooters="True" ShowGroupPanel="False"
AutoGenerateColumns="False" IsReadOnly="True" Grid.Row="3"
Grid.ColumnSpan="2" x:Name="RadGridView1"
CanUserFreezeColumns="False" GroupRenderMode="Flat"
RowIndicatorVisibility="Collapsed">
<interactivity:Interaction.Triggers>
<interactivity:EventTrigger EventName="RowActivated">
<shared:EventToCommandTrigger Command="{Binding UpdateStudentCommand}" />
</interactivity:EventTrigger>
</interactivity:Interaction.Triggers>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding StudentRollNo}" Header="Student Code" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding StudentRegNo}" Header="Reg No." />
<telerik:GridViewDataColumn DataMemberBinding="{Binding StudentEsisNo}" Header="Esis No." />
<telerik:GridViewDataColumn DataMemberBinding="{Binding StudentName}" Header="Student Name" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding UserName}" Header="User Name" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding AllocatedClass}" Header="Class" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Gender}" Header="Gender" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding DateOfBirth,StringFormat=dd/MM/yyyy}"
Header="Date Of Birth" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding ParentName}" Header="Parent Name" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding ParentMobile}" Header="Father Mob. No." />
<telerik:GridViewDataColumn DataMemberBinding="{Binding MotherMobile1}" Header="Mother Mob. No." />
<telerik:GridViewDataColumn DataMemberBinding="{Binding StudentType}" Header="Student Type" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<telerik:RadDataPager PageSize="100" Grid.Row="4"
FontSize="12" Margin="0,-1,0,0"
Source="{Binding Items, ElementName=RadGridView1}"
IsTotalItemCountFixed="false"
DisplayMode="FirstLastPreviousNextNumeric, Text" />
Whether I have to handle events of pagedcollection view? If so how to handle in MVVM Pattern?
Im using the code from from this link
and my Wix Dialogs looks like this
<Control Id="DummyComboBox" Hidden="yes" Type="ComboBox" Sorted="yes" ComboList="yes" Property="DUMMYPROPERTY" X="65" Y="60" Width="150" Height="18">
<ComboBox Property="DUMMYPROPERTY">
<ListItem Text="Dummy" Value="Dummy"/>
</ComboBox>
</Control>
<Control Id="SQLServer" Type="ComboBox" Sorted="yes" ComboList="yes" X="150" Y="100" Width="110" Height="18" Property="DBSERVER"/>
<Control Id="SQLServerLabel" Type="Text" X="25" Y="100" Width="90" Height="18" NoPrefix="yes" Text="!(loc.SQLServerLabel)"/>
<Control Id="SQLDatabaseName" Type="Edit" X="150" Y="120" Width="110" Height="18" Property="SQLDBNAME"/>
<Control Id="SQLDBServerLabel" Type="Text" X="25" Y="120" Width="90" Height="18" NoPrefix="yes" Text="!(loc.SQLDatabaseLabel)"/>
<Control Id="SQLUser" Type="Edit" X="150" Y="140" Width="110" Height="18" Property="SQLUSER"/>
<Control Id="SQLUServerLabel" Type="Text" X="25" Y="140" Width="90" Height="18" NoPrefix="yes" Text="!(loc.SQLUserLabel)"/>
<Control Id="SQLPassword" Type="Edit" X="150" Y="160" Width="110" Height="18" Property="SQLPASSWORD" Password="yes"/>
<Control Id="SQLPServerLabel" Type="Text" X="25" Y="160" Width="90" Height="18" NoPrefix="yes" Text="!(loc.SQLPasswordLabel)"/>
I have walked through the code and it's functioning properly. However when I display the Wix Dialog the combo box is empty. Any idea as to what I'm doing wrong
Quite simple ...
Hidden="yes"
Hidden="no"
You are hiding it.
You need to write custom actions to fill the combo boxes for e.g. for filling Server Instance combo box u may be write some thing like given below:-
public static ActionResult FillServerInstances(Session xiSession)
{
xiSession.Log("Begin CustomAction");
xiSession.Log("Opening view");
View lView = xiSession.Database.OpenView(
"DELETE FROM ComboBox WHERE ComboBox.Property='DBSRVR'");
lView.Execute();
lView = xiSession.Database.OpenView("SELECT * FROM ComboBox");
lView.Execute();
int Index = 1;
bool flag = false;
try
{
foreach (DataRow dr in Microsoft.SqlServer.Management.Smo.SmoApplication
.EnumAvailableSqlServers(false).Rows)
{
String InstanceName = dr["Name"].ToString();
if (InstanceName.Equals(xiSession["ComputerName"]
+ #"\"
+ xiSession["SQLINSTANCENAME"],
StringComparison.InvariantCultureIgnoreCase))
{ flag = true; }
Record lRecord = xiSession.Database.CreateRecord(4);
xiSession.Log("Setting record details");
lRecord.SetString(1, "DBSRVR");
lRecord.SetInteger(2, Index);
lRecord.SetString(3, InstanceName);
lRecord.SetString(4, InstanceName);
xiSession.Log("Adding record");
lView.Modify(ViewModifyMode.InsertTemporary, lRecord);
++Index;
}
}
catch (Exception ex)
{
logException(xiSession, ex);
}
if (flag)
{
xiSession["DBSRVR"] = xiSession["ComputerName"].ToString()
+ #"\" + xiSession["SQLINSTANCENAME"].ToString();
}
lView.Close();
xiSession.Log("Closing view");
lView.Close();
return ActionResult.Success;
}