XAML textbox updated when Textis entered in input - c#

I have a bunch of inputs that are being used to collect information. These inputs need to update the listname textbox on update.
I need to display it as Last Name space Suffix, First Name space Middle Initial. the Parth on each input is setting the text thats typed into the code to save it to the database on update. I am not sure where to go from here. Do I use a one way or two way mode? do I write it in c# and how?
<TextBox x:Uid="TextBox_1" Grid.Column="1" Grid.Row="0" Tag="{Binding Path=FirstNameLabel, Source={StaticResource Clientization}}" Style="{StaticResource EditTextBox}" MaxLength="35"
Text="{Binding Path=Provider.FirstName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_2" Grid.Column="2" Grid.Row="0" Tag="Middle" MinWidth="75" Style="{StaticResource EditTextBox}" MaxLength="30"
Text="{Binding Path=Provider.MiddleName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_3" Grid.Column="1" Grid.Row="1" Tag="{Binding Path=LastNameLabel, Source={StaticResource Clientization}}" Style="{StaticResource EditTextBox}" MaxLength="60"
Text="{Binding Path=Provider.LastName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_4" Grid.Column="2" Grid.Row="1" Tag="Suffix" Style="{StaticResource EditTextBox}" MaxLength="20"
Text="{Binding Path=Provider.Suffix, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_5" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2" Tag="List Name*" Style="{StaticResource EditTextBox}" MaxLength="160"
Text="{Binding Path=Provider.ListName, UpdateSourceTrigger=PropertyChanged}"/>
<TextBox x:Uid="TextBox_6" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="3" Tag="NPI*" Style="{StaticResource EditTextBox}" MaxLength="80"
Visibility="{Binding Path=HideNpi, Source={StaticResource Clientization}, Converter={StaticResource TernaryConverter}, ConverterParameter='True ? Collapsed : Visible'}"
Text="{Binding Path=Provider.NPI, UpdateSourceTrigger=PropertyChanged}"/>

I suggest you to use Entity Framework with your WPF application to binding with database, please check out below links for your reference:
http://msdn.microsoft.com/en-us/vstudio/Video/dd776537
http://msdn.microsoft.com/en-us/vstudio/Video/dd776540
And this:http://msdn.microsoft.com/en-us/library/cc716735.aspx
Hope it helps.

Related

C# WPF XAML , How create Textbox input field with stringformat?

Code XAML
<Grid>
<StackPanel Orientation="Horizontal">
<Label Content="Bank Doc Nbr :" Margin="0,0,0,0" VerticalAlignment="Center" />
<TextBox Name="txtBankNbr" Text="{Binding ElementName=txtBankNbr, Path=Text, StringFormat={}{0:##0/000}}" materialDesign:HintAssist.Hint="0/000" VerticalAlignment="Center" materialDesign:TextFieldAssist.DecorationVisibility="Hidden" BorderThickness="0" />
<Label Content="Bank Income :€" Margin="5,0,0,0" VerticalAlignment="Center" />
<TextBox Name="txtBankIncome" Text="{Binding ElementName=txtBankIncome, Path=Text,StringFormat={}{0:######0.00}}" materialDesign:HintAssist.Hint="0,00" VerticalAlignment="Center" materialDesign:TextFieldAssist.DecorationVisibility="Hidden" BorderThickness="0" />
</StackPanel>
</Grid>
------ Explanation: Format of txtBankNbr is {0:##0/000} and can only receive numbers. eg "1/001" , 12/021 , ....
Format of txtBankNbr is {0:##0.00} and can only receive a decimal
number What is wrong in my code?
Thanks
Try this:
StringFormat={}{0:#.##}
it should show two decimal place

Binding data to XAML while runtime

I build a Chart with a Grid and some Rectangles, like in this Post:
Drawing a chart in WPF C# design questions
Now I save this Chart to an XAML-File to fill it later by another program.
In this chart I need to bind three Values:
1. Labels
2. MaxHeight - Height (by each bar)
3. Height
My Problem is, that I don't know how to bind it correctly for using it in another application.
The other Application could give me a list or an array with the values and the label, but I dont know how I should bind unknown values to the Rectangles.
In the code below I binded the "ChartLabel" but I need all Chart Labels not only one.
When I creating the chart I don't now how much bars I will have later.
<Grid ShowGridLines="True" Background="#FFF5F5DC" Width="Auto" Margin="5,5,5,5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Rectangle Fill="#FF0000FF" Grid.Column="{Binding Path=Test6_Val, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=ChartLabel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderBrush="#00FFFFFF" Background="#00FFFFFF" HorizontalAlignment="Center" Grid.Column="5" Grid.Row="10" />
<Rectangle Fill="#FF0000FF" Grid.Column="{Binding Path=Test7_Val, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=ChartLabel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderBrush="#00FFFFFF" Background="#00FFFFFF" HorizontalAlignment="Center" Grid.Column="6" Grid.Row="10" />
<Rectangle Fill="#FF0000FF" Grid.Column="{Binding Path=Test8_Val, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=ChartLabel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderBrush="#00FFFFFF" Background="#00FFFFFF" HorizontalAlignment="Center" Grid.Column="7" Grid.Row="10" />
<Rectangle Fill="#FF0000FF" Grid.Column="{Binding Path=Test9_Val, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=ChartLabel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderBrush="#00FFFFFF" Background="#00FFFFFF" HorizontalAlignment="Center" Grid.Column="8" Grid.Row="10" />
<Rectangle Fill="#FF0000FF" Grid.Column="{Binding Path=Test10_Val, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{Binding Path=ChartLabel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" BorderBrush="#00FFFFFF" Background="#00FFFFFF" HorizontalAlignment="Center" Grid.Column="9" Grid.Row="10" />
</Grid>
I'm not sure I follow your description of which part you're having a problem with.
You will have a List.
You want to use a string from that as label and a number as height.
If you iterate that you can find the max and hence calculate some sort of scaling factor so a value of half the max ends up about half the height of your chart.
The way I'd do a series like that is with an itemscontrol. Bind an observablecollection to the itemssource. An itemscontrol has a stackpanel it's contents go in. Make the orientation horizontal and define an itemtemplate. That would have a textblock for the label, (maybe rotated) and a rectangle whose height is bound to your scaled value.
Which is roughly how the terrain visualiser I wrote works.
There are no labels - so this is to give you the idea rather than cut and paste.
<ListBox ItemsSource="{Binding TerrainPointList}"
..
>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="True"
Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
...
A listbox has scrollers and selecteditem. I use selecteditem in mine and that might or might not be useful to you.

SL4 Dataform NewItemTemplate textbox value not getting bound

I have a silverlight 4 application using MVVM which has a grid and dataform. the dataform
has an EditItemTemplate and a NewItemTemplate. On Editing the EditItemTemplate code runs fine but upon adding a new item the NewItemTemplate code throws an error to the effect that barcode is required. Where could I be going wrong. Thanks in advance.
NewItemTemplate xaml code
<toolkit:DataField Label="Barcode :"
FontWeight="Bold"
Grid.Column="0"
Grid.Row="0"
Margin="1"
IsRequired="True"
HorizontalAlignment="Left">
<TextBox Grid.Column="1"
Name="BarcodeId"
Text="{Binding Barcode.BarcodeId,Mode=TwoWay, NotifyOnValidationError=True,ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Stretch"
Grid.Row="0"
Margin="2"
Width="300"
TabIndex="0" />
</toolkit:DataField>
EditItemTemplate code
<toolkit:DataField Label="Barcode :"
FontWeight="Bold"
Grid.Column="0"
Grid.Row="0"
Margin="1"
IsRequired="False"
IsEnabled="True"
HorizontalAlignment="Left">
<TextBox Width="200"
Text="{Binding Barcode.BarcodeId,Mode=TwoWay}" FontWeight="Normal" />
</toolkit:DataField>

Show only allowed data in WPF Listbox Databinding

I currently have a list box:
<ListBox HorizontalAlignment="Left"
ItemsSource="{Binding Data, ElementName=bookingDomainDataSource}"
Margin="158,134,0,45"
x:Name="bookingListBox"
Width="429"
SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay, ElementName=bookingComboBox}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=userId}"
Width="100" />
<TextBlock Text="{Binding Path=bookingName}"
Width="100" />
<TextBlock Text="{Binding Path=bookingDate}"
Width="100" />
<TextBlock Text="{Binding Path=showId}"
Width="100" />
<TextBlock Text="{Binding Path=paymentId}"
Width="100" />
<TextBlock Text="{Binding Path=ticketId}"
Width="100" />
<TextBlock Text="{Binding Path=ticketQuantity}"
Width="100" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
And I would like to only show rows from the itemssource that have a certain userId, how can I do this?
Thanks.
I think the best solution to this would be to filter the data source BEFORE you get to the front end.
You want to define a filter for your listview.
Uodate: sorry missed the silverlight tag. However CollectionViewSource should still be useful to you. Here a sample using the CollectionViewSource in Silverlight.

Data binding in pivot TitleTemplate for Windows Phone

I must be missing something simple here...I am writing a Windows Phone 7 app and I have customized my pivot header to be the following:
<controls:Pivot Name="InfoPivot">
<controls:Pivot.TitleTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,0" VerticalAlignment="Top">
<Rectangle Fill="{Binding CategoryFill}" Height="50" Width="50" Margin="355,25,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Name="CategoryRect" />
<StackPanel Margin="-425,-14,0,0" Width="432">
<TextBlock x:Name="StationTitle" Text="{Binding StationTitle}" Margin="10,0,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
<TextBlock Name="LocationTitle" Text="{Binding LocationTitle}" TextWrapping="Wrap" Margin="12,0,0,20" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</controls:Pivot.TitleTemplate>
When I navigate to this page, I pass Station and Location as parameters, and in the OnNavigatedTo() for this page I try to set the StationTitle and LocationTitle. Unfortunately, I end up getting:
Error 2 The name 'StationTitle' does not exist in the current context
How should/do we go about accessing members in the Pivot TitleTemplate? Any help will be appreciated! Thanks.
Stop using the title template and binding to acheive this. Try this instead:-
<controls:Pivot Name="InfoPivot">
<controls:Pivot.Title>
<StackPanel Orientation="Horizontal" Margin="0,0,0,0" VerticalAlignment="Top">
<Rectangle Fill="{Binding CategoryFill}" Height="50" Width="50" Margin="355,25,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Name="CategoryRect" />
<StackPanel Margin="-425,-14,0,0" Width="432">
<TextBlock x:Name="StationTitle" Margin="10,0,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
<TextBlock x:Name="LocationTitle" TextWrapping="Wrap" Margin="12,0,0,20" Style="{StaticResource PhoneTextNormalStyle}"/>
</StackPanel>
</StackPanel>
</controls:Pivot.Title>
Then in code-behind:-
if (NavigationContext.QueryString.TryGetValue("Station", out station))
{
StationTitle.Text = station;
}
if (NavigationContext.QueryString.TryGetValue("LocationTitle", out locationTitle))
{
LocationTitle.Text = locationTitle;
}
Without seeing all of your code, this may be as simple as making the Name declaration consistent on your two TextBlocks.
Note, one is Name="", the other is x:Name="".
Defining the template inline worked for me, The TitleTemplate just wouldn't work.
<phone:Pivot>
<phone:Pivot.Title>
<TextBlock Margin="0"
Text="{Binding Exercise.Name}"
Style="{StaticResource MainTitleStyle}"/>
</phone:Pivot.Title>
</phone:Pivot>

Categories