How to show part of text in datagrid row details? - wpfdatagrid

I have table in my database which has fields of ID,NAME,CONTEXT. I am showing search result in datagrid. Now I tried to do this
<WpfToolkit:DataGrid.RowDetailsTemplate>
<DataTemplate>
**<StackPanel Orientation="Horizontal" Margin="5">
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Foreground="CadetBlue" FontSize="13"
Width="Auto" TextWrapping="Wrap"
Text="{Binding Path=Context}"/>
</StackPanel>**
</StackPanel>
</DataTemplate>
</WpfToolkit:DataGrid.RowDetailsTemplate>
It is giving whole text which is not what I want. If you give me some directions how to do this, may be some code. It will be appreciated. I want to show only that part of text which is selected by this line of code.
private void Find_Click(object sender, RoutedEventArgs e)
{
DataSet ds = new DataSet();
cmdSel = new SqlCommand();
cmdSel.Connection = MainWindow.conn;
cmdSel.CommandText = "select id,Name,Context from document where Contains([Context],'FormsOf (INFLECTIONAL, \"" + TextBoxSearch.Text + "\")')";
da = new SqlDataAdapter(cmdSel);
da.Fill(ds, "MainSearchBinding");
resWin.DataGrid1.DataContext = ds;
}
For example you are searching for "audio" and it is showing 10 words before + "audio" + 10 word after audio. Thank in advance.

I add one more column "Intro" to my table.
<WpfToolkit:DataGrid.RowDetailsTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="5">
<StackPanel Orientation="Vertical" Margin="5" >
<TextBlock Foreground="CadetBlue" FontSize="13"
Width="Auto" TextWrapping="Wrap"
Text="{Binding Path=Intro}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</WpfToolkit:DataGrid.RowDetailsTemplate>
And wrote this code for mouse click.
private void OnMouseClick(object sender, MouseButtonEventArgs e)
{
IList rows = DataGrid1.SelectedItems;
DataRowView row = (DataRowView)DataGrid1.SelectedItems[0];
int a = (int)row["ID"];
string t = (string)row["Context"]; //getting all text from Context
string srch1 = UCSearch.srch; // search box text
if (t.IndexOf(srch1) != -1)
{
string retString = t.Substring(t.IndexOf(srch1), 100); //cutting from occured text and more 100 symbols
row["Intro"] = retString; // setting to Intro Column
}
}
I hope some one may need it. Thank you.

Related

RadCombobox does not show correct property value

I'm unable to "clear" the current selection from a RadCombobox when needed. This RadCombobox is rebound with new data depending on the value of another radcombobox. After the rebinding, the prior selection should be cleared out. But it still displays. If the prior selection was "OAK", then the combobox still shows OAK as a selection when it should be blank. I find radcomboboxes very tricky to set up so I'm sure it's something dumb on my part.
The Text property of the combobox is bound to woodSpecies which is set up below:
<telerik:RadComboBox x:Name="cboWoodSpecies"
FontSize="16" Background="#F6F8FA" BorderBrush="#D7D8DD"
ItemsSource="{Binding}"
SelectedValue="theWoodSpecies"
Text="{Binding woodSpecies}"
telerik:TextSearch.TextPath="theWoodSpecies"
IsEditable="True"
Style="{DynamicResource RadComboBoxStyle3}" >
<telerik:RadComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding theWoodSpecies}"/>
<TextBlock Grid.Column="1" Text="{Binding WoodSpeciesUpchargeDisplay}"/>
<TextBlock Grid.Column="2" Text="{Binding WoodSpeciesUpcharge}" Visibility="Hidden"/>
</Grid>
</DataTemplate>
</telerik:RadComboBox.ItemTemplate>
</telerik:RadComboBox>
Private _woodSpecies As String
Public Property woodSpecies As String
Get
Return _woodSpecies
End Get
Set(value As String)
_woodSpecies = value
NotifyPropertyChanged("woodSpecies")
End Set
End Property
When it's time to clear the prior selection, this code is run:
thisOrder = New Order 'sets woodSpecies to empty string. Verified by debug.
cboWoodSpecies.SelectedIndex = -1 ' A debug break here shows that thisOrder.woodSpecies is empty string
The only way I can blank out the radcombobox is by using this code below. But I thought that was the whole point of INotifyPropertyChanged.
cboWoodSpecies.Text = String.Empty
How to fix this? Thanks.
I forgot to add Mode=TwoWay to Text="{Binding woodSpecies}"

uwp twoway binding not updating UI

I have the following XAML code, where I have a TextBox for user input (phone number) and GridView for user contacts.
<GridView x:Name="ContactsCollection" Grid.Row="1" Style="{StaticResource DefaultGridView}" IsItemClickEnabled="True" ItemsSource="{Binding UserContacts}" ItemTemplate="{StaticResource HorizontalGridViewDataTemplate}" ItemContainerStyle="{StaticResource DefaultGridViewItemContainer}">
<i:Interaction.Behaviors>
<c:EventTriggerBehavior EventName="SelectionChanged">
<c:InvokeCommandAction Command="{Binding SelectContactCommand}" CommandParameter="{Binding SelectedItem, ElementName=ContactsCollection}"/>
</c:EventTriggerBehavior>
</i:Interaction.Behaviors>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
And my TextBox that is binded to the Recipient in the ViewModel.
<TextBox x:Uid="Recipient" Text="{Binding Recipient, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" PreventKeyboardDisplayOnProgrammaticFocus="True" toolkitControls:TextBoxMask.Mask="7(999)999-99-99" toolkitControls:TextBoxMask.PlaceHolder="X" InputScope="NumericPin" HeaderTemplate="{StaticResource UiControlHeaderDataTemplate}" Style="{StaticResource DefaultTextBoxStyle}"/>
Here goes code from the ViewModel.
public string Recipient
{
get { return _recipient; }
set
{
if (value != _recipient)
{
_recipient = value;
RaisePropertyChanged(nameof(Recipient));
ContinueTransferCommand.RaiseCanExecuteChanged();
}
}
}
Now, when I click any contact from the GridView the following functions is called, that assign contact's phone number to the Recipient property.
private void SelectContactCommandAction(object contact)
{
Contact c = contact as Contact;
if (c.Phones?.Count > 0)
Recipient = FormatDataHelper.FormatPhoneNumber(c.Phones.FirstOrDefault().Number);
}
When I click any contact for the FIRST time, the Recipient property is updated, and the UI is updated too. But, if I select other contact, in the debug mode I can see, that Recipient property is updated and saved new value, but the UI (TextBox) is not updated at all. The only way it works, I have to delete any character from the TextBox and select a contact again, in that case UI value will be updated again.
Can somebody please explain this?

Pivot control header icon of un selected pivot in windows phone universal application

I have pivot control in my universal windows phone application. Defined like this
<PivotItem.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Margin="0 0 10 0" Width="40" Source="/Assets/Images/cher.png" />
<TextBlock x:Uid="cherTextBlock" Grid.Column="1" Style="{StaticResource PivotHeadingStyle}" />
</Grid>
</PivotItem.Header>
When I am on first pivot the text of second pivot becomes dull. But offcourse the image doesn't become dull. I have same image with dull effect and I want that dul image to be shown when other pivot is shown.
One approach is that I make it programmatically and change the source of image when it is not in focus. But I want to know is that possible to do this in xaml or some other better approach than mine?
Accomplished it like programmatically
inside initialized component added this code
//RechargeAccountPivot is name of my pivot control.
RechargeAccountPivot.SelectionChanged += RechargeAccountPivot_SelectionChanged;
And this is selectionChanged event code. where i gave names to my all image controls and changed their icons.
private void RechargeAccountPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (RechargeAccountPivot.SelectedIndex == 0)
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCard.png"));// new BitmapImage { UriSource = new Uri("//Assets/Images/BalanceTopUpIcons/rechargeCard.png") };
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
}
else if (RechargeAccountPivot.SelectedIndex == 1)
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCardDull.png"));
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucher.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
}
else
{
PivotOneImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/rechargeCardDull.png"));
PivotTwoImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucherDull.png"));
PivotThreeImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/Images/BalanceTopUpIcons/eVoucher.png"));
}
}

Get the TextBlock in a ListView in Windows 8.1

I am using Windows 8.1. I have a ListView which populates using ItemsSource property.
And in my ListView.ItemTempalte, it has a TextBox.
<ListView
ItemsSource="{Binding CollectionGroups, Source={StaticResource GroupedData}}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Group.Property1}"
Foreground="Black" FontSize="18" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My question is how can I get the last item text box in my C# code? The code behind for the xaml page that I show above? For example, I have 10 items in my CollectionGroups, my list view should have 10 text box. How can I get the 10th Text box of the list view?
Thank you.
First off, you need to assign names to your markup:
<ListView
ItemsSource="{Binding CollectionGroups, Source={StaticResource GroupedData}}" x:Name="lvGroupData">
<ListView.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Group.Property1}"
Foreground="Black" FontSize="18" x:Name="tbProperty1" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Then you need a VisualTreeHelper method (this is the standard way, you will find methods that are more or less like this one all over the web):
public T FindElementByName<T>(DependencyObject element, string sChildName) where T : FrameworkElement
{
T childElement = null;
var nChildCount = VisualTreeHelper.GetChildrenCount(element);
for (int i = 0; i < nChildCount; i++)
{
FrameworkElement child = VisualTreeHelper.GetChild(element, i) as FrameworkElement;
if (child == null)
continue;
if (child is T && child.Name.Equals(sChildName))
{
childElement = (T)child;
break;
}
childElement = FindElementByName<T>(child, sChildName);
if (childElement != null)
break;
}
return childElement;
}
Now you can access the element you need:
this.UpdateLayout();
// Get the last item here
var lvItem = this.lvGroupData.Items[this.lvGroupData.Items.Count - 1];
var container = this.lvGroupData.ContainerFromItem(lvItem);
// NPE safety, deny first
if (container == null)
return;
var textboxProperty1 = FindElementByName<TextBox>(container, "tbProperty1");
// And again deny if we got null
if (textboxProperty1 == null)
return;
/*
Start doing your stuff here.
*/

How to add autocomplete functionality for Listpicker in windows phone 8?

Hi I'm developing wp8 application .
I'm using List picker for bind city names.Below it's my code for list Picker
XAML
<toolkit:ListPicker x:Name="Lpcity" Foreground="White" BorderThickness="0" VerticalAlignment="Top" Margin="400,10,0,0" Height="80" Width="50" Visibility="Visible" SelectionChanged="Lpcity_SelectionChanged">
<toolkit:ListPicker.Background>
<ImageBrush ImageSource="/Assets/Images/search.png"/>
</toolkit:ListPicker.Background>
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding cityname}" Visibility="Collapsed" Foreground="Red"/>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock FontSize="30">
<Run Text="{Binding cityname}"/>
</TextBlock>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
C#
public void Citybind()
{
string city_nameurl = "http://xxxx.yyyyy";
WebClient city_namewc = new WebClient();
city_namewc.DownloadStringAsync(new Uri(city_nameurl), UriKind.Relative);
city_namewc.DownloadStringCompleted += city_namewc_DownloadStringCompleted;
}
void city_namewc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var city_name = e.Result;
city_namedata add = new city_namedata();
add.id = "-1";
add.cityname = "Select any one city";
add.id = "0";
add.cityname = "Remove city based search";
var city_nameval = JsonConvert.DeserializeObject<List<city_namedata>>(city_name);
city_nameval.Insert(0, add);
Lpcity.ItemsSource = city_nameval;
}
OutPut:
Now nearly 200 and more city name is bind in List picker. If user wan to select city name start with z. now he need to scroll to the bottom of the screen.
So i need to add the auto complete functionality . If user type z all z related name should show to user.
I searched in web and find out autocomplete box functionality.I try with following code for autocomplete box
XAML
<toolkit:AutoCompleteBox HorizontalAlignment="Left"
Width="450"
Grid.Row="0"
Name="autoCompleteBox1"
VerticalAlignment="Top"
InputScope="Digits"
ItemsSource="{StaticResource AutoCompletions}"
/>
Now i need to know it's possible to add both list picker and autocomplete box?
Other wise any other option available for my requirement?
Thank you