Hi Paul Betts and Matt Oswald.. Thanks for your valuable replay. I am newbie to app development. Now only learning. So can you please provide me a simple sample.
For Example here with i will attach my sample:
Xaml:-
<Rectangle Height="30" HorizontalAlignment="Left" Margin="48,66,0,0" Name="rectangle1" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="210" Fill="White" />
<Rectangle MaxWidth="210" Height="30" HorizontalAlignment="Left" Margin="48,66,0,0" Name="rectangle2" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="{Binding rectWidth}" Fill="Orange" />
<Button Command="{Binding withCalculate}" Content="Calculate" Height="72" HorizontalAlignment="Left" Margin="256,102,0,0" Name="button1" VerticalAlignment="Top" Width="160" />
<TextBox InputScope="Number" Height="72" HorizontalAlignment="Left" Margin="88,102,0,0" Name="textBox1" Text="{Binding widthText, Mode=TwoWay}" VerticalAlignment="Top" Width="182" KeyUp="textBox1_KeyUp" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="43,30,0,0" Name="textBlock1" Text="Fill the Rect With Given %" VerticalAlignment="Top" FontSize="26" FontFamily="Times New Roman" FontWeight="Bold" FontStyle="Italic" />
<TextBlock Height="30" HorizontalAlignment="Left" Margin="24,126,0,0" Name="textBlock2" Text=" % =" VerticalAlignment="Top" FontSize="28" />
Xaml.CS:-
public partial class RoughPage : PhoneApplicationPage
{
public RoughPage()
{
InitializeComponent();
RoughPageUIContainer.DataContext = new RoughPageViewModel();
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
TextBox textBox = sender as TextBox;
BindingExpression bindingExpr = textBox.GetBindingExpression(TextBox.TextProperty);
bindingExpr.UpdateSource();
}
}
View Model:-
namespace NewExample.ViewModel
{
public class RoughPageViewModel : ReactiveObject
{
public static double _rectWidth;
public double rectWidth
{
get { return _rectWidth; }
set { this.RaiseAndSetIfChanged(x => x.rectWidth, value); }
}
public static double _widthText;
public double widthText
{
get { return _widthText; }
set { this.RaiseAndSetIfChanged(x => x.widthText, value); }
}
public ReactiveAsyncCommand withCalculate { get; set; }
public RoughPageViewModel()
{
withCalculate = new ReactiveAsyncCommand();
withCalculate.Subscribe(x=>
{
double width = widthText;
double totWidth = 210;
rectWidth = widthText * (totWidth / 100);
});
}
}
}
Like this please provide me a sample. I know this is not a good way to ask. But i don't have any other way.
Here i will attach my listbox example also. If it is possible please just correct in my coding.
My Xaml:-
<Grid x:Name="listBoxExample" Grid.Row="1" Margin="2,0,2,0">
<TextBlock HorizontalAlignment="Left" Margin="137,6,0,0" Name="textBlock1" Text="ListBox Example" VerticalAlignment="Top" FontFamily="Times New Roman" FontSize="26" />
<ListBox ItemContainerStyle="{StaticResource MyStyle}" Height="400" ItemsSource="{Binding StudentDetails,Mode=TwoWay}" HorizontalAlignment="Left" Margin="0,35,0,0" Name="listBox1" VerticalAlignment="Top" Width="476" BorderBrush="#00410D0D">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Gray" Padding="5" BorderThickness="1">
<StackPanel Orientation="Horizontal" ManipulationStarted="ManipulationStart" ManipulationCompleted="ManipulationComplet">
<Border BorderBrush="Wheat" BorderThickness="1">
<Image Name="ListPersonImage" Source="{Binding PersonImage}" Height="100" Width="100" Stretch="Uniform" Margin="10,0,0,0"/>
</Border>
<TextBlock Text="{Binding FirstName}" Name="firstName" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22" />
<TextBlock Text="{Binding LastName}" Name="lastName" Width="200" Foreground="White" Margin="-200,50,0,0" FontWeight="SemiBold" FontSize="22" />
<TextBlock Text="{Binding Age}" Name="age" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Xaml.Cs:-
namespace NewExample.Views
{
public partial class ListBoxExample : PhoneApplicationPage
{
public ListBoxExample()
{
InitializeComponent();
listBoxExample.DataContext = new ListBoxExampleViewModel();
}
}
}
View Model:-
namespace NewExample.ViewModel
{
public class ListBoxExampleViewModel : ReactiveObject
{
public static ObservableCollection<ListBoxExampleModel> _StudentDetails;
public ObservableCollection<ListBoxExampleModel> StudentDetails
{
get { return _StudentDetails; }
set { this.RaiseAndSetIfChanged(x => x.StudentDetails, value); }
}
XDocument myData = XDocument.Load("Student.xml");
public ListBoxExampleViewModel()
{
var getOrgDetails = new ReactiveAsyncCommand();
getOrgDetails.Subscribe(x =>
{
StudentDetails = new ObservableCollection<ListBoxExampleModel>();
StudentDetails = ListBoxExampleModel.extract(myData.ToString());
});
getOrgDetails.Execute(true);
}
}
}
Model:-
namespace NewExample.Model
{
public class ListBoxExampleModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Age { get; set; }
public string PersonImage { get; set; }
public static ObservableCollection<ListBoxExampleModel> extract(string result)
{
ListBoxExampleModel lgp = new ListBoxExampleModel();
ObservableCollection<ListBoxExampleModel> content = new ObservableCollection<ListBoxExampleModel>();
XDocument xdoc = XDocument.Parse(result);
var res = from query in xdoc.Descendants("student")
select query;
for (int i = 0; i < res.Count(); i++)
{
lgp.FirstName = res.ElementAt(i).Element("firstname").Value;
lgp.LastName = res.ElementAt(i).Element("lastname").Value;
lgp.Age = res.ElementAt(i).Element("age").Value;
lgp.PersonImage = res.ElementAt(i).Element("photo").Value;
content.Add(lgp);
lgp = new ListBoxExampleModel();
}
return content;
}
}
}
Please let me know how to write tab event in View Model. Here i want to select the item and i want to navigate to another page.
(Forgive me for poor English). Looking for help from experts.. Thanks in advance..