I put the RichTextBox in my Silverlight App. Do I have to create my own set of buttons to use it? I want to have a standard set of editing buttons for the text box.
Unfortunately it's just the textbox not a whole suite of controls too like the toolbar, which is something you get with commercial WPF/Silverlight rich text boxes.
You tie your buttons up to format code as shown here:
//Set Bold formatting to selected content
private void BtnBold_Click(object sender, RoutedEventArgs e)
{
object o = MyRTB.Selection.GetPropertyValue(TextElement.FontWeightProperty);
if (o.ToString() != "Bold")
MyRTB.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
}
//<SnippetItalic>
//Set Italic formatting to selected content
private void BtnItalic_Click(object sender, RoutedEventArgs e)
{
object o = MyRTB.Selection.GetPropertyValue(TextElement.FontWeightProperty);
if (o.ToString() != "Italic")
MyRTB.Selection.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic);
}
//Set Underline formatting to selected content
private void BtnUnderline_Click(object sender, RoutedEventArgs e)
{
object o = MyRTB.Selection.GetPropertyValue(TextElement.FontWeightProperty);
if (o.ToString() != "Underline")
MyRTB.Selection.ApplyPropertyValue(TextElement.TextDecorationsProperty, TextDecorations.Underline);
}
To give your Silverlight app a formatting toolbar with a Mircosoft Office-style feel, check out the MSDN Silverlight Text Editor example.
Related
In Windows 8.1, I'm using the new SettingsFlyout control. The flyout animates in correctly and will animate out if you use the control's built-in back button to return to the Settings Charm flyout. But if you light dismiss by clicking outside the flyout, it disappears without a transition animation.
How do you animate a transition out when you light dismiss the SettingsFlyout? (I don't want to return to the Settings Charm flyout, I just want it to slide out on a light dismiss.)
Matt, what you want to do should be easily achievable but is currently not supported by the XAML SettingsFlyout API out of the box. As Jerry points out, there are transitions that allow an animate out effect (in XAML you want EdgeUIThemeTransition). Unfortunately, there is no API support on SettingsFlyout to add this transition, but you can get it to work using your own private popup to host the SettingsFlyout (more on this below):
public sealed partial class SettingsFlyout1 : SettingsFlyout
{
Popup _p;
Border _b;
public SettingsFlyout1()
{
this.InitializeComponent();
BackClick += SettingsFlyout1_BackClick;
Unloaded += SettingsFlyout1_Unloaded;
Tapped += SettingsFlyout1_Tapped;
}
void SettingsFlyout1_BackClick(object sender, BackClickEventArgs e)
{
_b.Child = null;
SettingsPane.Show();
}
void SettingsFlyout1_Unloaded(object sender, RoutedEventArgs e)
{
if (_p != null)
{
_p.IsOpen = false;
}
}
void SettingsFlyout1_Tapped(object sender, TappedRoutedEventArgs e)
{
e.Handled = true;
}
public void ShowCustom()
{
_p = new Popup();
_b = new Border();
_b.ChildTransitions = new TransitionCollection();
// TODO: if you support right-to-left builds, make sure to test all combinations of RTL operating
// system build (charms on left) and RTL flow direction for XAML app. EdgeTransitionLocation.Left
// may need to be used for RTL (and HorizontalAlignment.Left on the SettingsFlyout below).
_b.ChildTransitions.Add(new EdgeUIThemeTransition() { Edge = EdgeTransitionLocation.Right });
_b.Background = new SolidColorBrush(Colors.Transparent);
_b.Width = Window.Current.Bounds.Width;
_b.Height = Window.Current.Bounds.Height;
_b.Tapped += b_Tapped;
this.HorizontalAlignment = HorizontalAlignment.Right;
_b.Child = this;
_p.Child = _b;
_p.IsOpen = true;
}
void b_Tapped(object sender, TappedRoutedEventArgs e)
{
Border b = (Border)sender;
b.Child = null;
}
}
Full solution for this sample: https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/SettingsFlyout_AnimateOut
I think SettingsFlyout should have API support for your scenario, so I filed a work item on the XAML team. In the future, such requests/issues can be raised on the MSDN forum as well (moderated by MSFT folks). The limitation here is that SettingsFlyout is implemented on top of Popup with IsLightDismissEnabled="True", and the light-dismiss event currently closes the Popup immediately without allowing unloading child transitions to run. I think this can be overcome and transitions can be supported at the SettingsFlyout API level to enable your scenario.
You need to use the HideEdgeUI animation
Read this: http://msdn.microsoft.com/en-us/library/windows/apps/jj655412.aspx
I am using http://christian-helle.blogspot.in/2011/01/multi-platform-mobile-development_19.html for creating a custom list view.
In the existing sample it is not possible to pre set the selectedIndex of list view.
I have made few changes to the sample code and I am able to set the index and highlight it. but the problem is I am not able to set the scroll position to the highlighted item.
I have tried to set scrollBar.Value = itemindex, but it is not reflecting on the custom list view.
The simplest solution would be ListView.EnsureVisible.
private ListView listView1;
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (-1 < listView1.SelectedIndex) {
listView1.EnsureVisible(listView1.SelectedIndex);
}
}
i have a pivot page with 3 pages and there are two application bar buttons. But i want that when pivot is changed, the first button of application bar should do different tasks on different pivot, and second button will do same task on all pivots. I am doing this as:
private void PivotControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ApplicationBarIconButton firstButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
if (PivotControl.SelectedIndex == 0)
{
firstButton.IsEnabled = true;
firstButton.Click += new EventHandler(FirstPivotButton_Click);
}
else if (PivotControl.SelectedIndex == 1)
{
firstButton.IsEnabled = true;
firstButton.Click += new EventHandler(SecondPivotButton_Click);
}
else if (PivotControl.SelectedIndex == 2)
{
firstButton.IsEnabled = false;
}
}
void FirstPivotButton_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/PageA.xaml", UriKind.Relative));
}
void SecondPivotButton_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/PageB.xaml", UriKind.Relative));
}
But the problem is that PageA is being navigated well but there is problem in going to PageB from secondpivotbutton click event. Please help me
Use this great library for simplifying usage of ApplicationBar on Windows Phone - AppBarUtils.
You can find them on NuGet as well.
There is also nice tutorial, how ti display different buttons for each panorama/pivot item using this library:
http://allenlooplee.wordpress.com/2012/09/17/how-to-show-different-app-bar-for-different-pivotpano-item/
Here's how I did this in one of my apps. Button 1 is different for pivot pages and button 2 is always the same, just like you.
On the SelectionChanged event, update the button icon uri and text:
Private Sub statPivot_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles statPivot.SelectionChanged
Dim saveBtn As ApplicationBarIconButton = ApplicationBar.Buttons(0)
If statPivot.SelectedIndex = 0 Then
'calculation pane active
saveBtn.Text = "save"
saveBtn.IconUri = New Uri("/Assets/AppBar/appbar.save.rest.png", UriKind.Relative)
Else
'history pane active
saveBtn.Text = "clear"
saveBtn.IconUri = New Uri("/Assets/AppBar/appbar.refresh.rest.png", UriKind.Relative)
End If
End Sub
then in the onclick event I detect the pivot pane that's being viewed and use a basic if...then...else... to run the different code within the same handler.
If you want dynamically change app bar buttons at run time you can do this:
<phone:PhoneApplicationPage.Resources>
<shell:ApplicationBar x:Key="appbar1" IsVisible="True">
<shell:ApplicationBarIconButton x:Name="abMain1" IconUri="/icons/appbar.favs.addto.rest.png" Text="blabla1"/>
</shell:ApplicationBar>
<shell:ApplicationBar x:Key="appbar2" IsVisible="True">
<shell:ApplicationBarIconButton x:Name="abMain2" IconUri="/icons/appbar.favs.addto.rest.png" Text="blabla2"/>
<shell:ApplicationBarIconButton x:Name="abMain3" IconUri="/icons/appbar.cancel.rest.png" Text="blabla3"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.Resources>
And then change it from code:
ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar) Resources["appbar1"];
and
ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar) Resources["appbar2"];
You can big numbers of different AppBars.
Hope its help.
I have the following XAML code
XAML:
<Button x:Name = "Btn1" Click = "Button_Click">
can i change the color of the font in the Button_Click method or anywhere else in code?
You can implement it by the following code runs in directX 2013:
void App2::DirectXPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) {
bt->Foreground = ref new SolidColorBrush(Windows::UI::Colors::Blue);
}
Yes you can change the color of the button any where in the code
Here's a sample button and a sample code to change color in it's click event
Heres the code to change the color in the click event of the btnChangeFontColor
private void Button_Click_1(object sender, RoutedEventArgs e)
{
btnChangeFontColor.Foreground = new SolidColorBrush(Colors.Red);
}
I'm using gridview with templates to show and edit some information from a sql database.
When I edit and change the data in that row and then click enter it automatically presses the highest on page button which uses submit to server set to true which means it'll try to delete instead of update.
I've have tried setting a panel round the gridview and setting the panel's default button to the "updatebutton" but it won't allow that because it can't 'see' the buttons.
I had a similar problem and I found a very simple workaround:
Place a button below the GridView and make it invisible by CSS (i.e. position: relative; left: -2000px)
Create a Panel around the GridView and give it as DefaultButton the ID of the button we just created.
Write the following line of code for the click-event of the button:
myGridView.UpdateRow(myGridView.EditIndex, false);
Whenever you press enter in the GridView now, the edited row will be confirmed.
You need to precess KeyDown or KeyPress event of the grid, and check if pressed key if Keys.Enter :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1_Click(this, EventArgs.Empty);
}
}
private void button1_Click(object sender, EventArgs e)
{
// Your logic here
}
}