This is a Water Hackathon, 2014 Project.
I am a newbie in windows phone. I was developing an app for a project. part of the app is that user will write his number and some text and the number and text will be emailed to a particular person.
I used drag n drop UI and wrote the code of email send in Visual C#. Here is the error:
Failed to assign to property 'System.Windows.UIElement.AllowDrop'.[Line: 53 Position: 76]
at
System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at
PhoneApp2.MainPage.InitializeComponent()
at PhoneApp2.MainPage..ctor()
part of the C# code:
private void emailSend(object sender, RoutedEventArgs e)
{
// Create a new instance of the class EmailComposeTask with which you can send email
var emailcomposer = new EmailComposeTask
{
// I enter the recipients to send the email using the To property of the class
EmailComposeTask
To = string.Concat("mailto:","ibtehaz.shawon#gmail.com"),
// Set the title of the property by Subject
Subject = "number",
// Enhanced the value of the Body property EmailComposeTask class, this is the
content that will display the recipient
Body = bigText.Text,
};
// Start the email application on your device to send the Email
emailcomposer.Show();
}
part of the XAML file:
<TextBlock Text="Wheres the problem" Style="{StaticResource PhoneTextNormalStyle}"
FontSize="36" FontFamily="Andalus"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="10,0,14,0"
RenderTransformOrigin="0.463,0.232">
<TextBox Name="number" HorizontalAlignment="Left" Height="88" Margin="0,98,0,0"
TextWrapping="Wrap" Text="Please enter your phone number" VerticalAlignment="Top"
Width="456"/>
<TextBlock Name="bigText" HorizontalAlignment="Left" AllowDrop="True" TextWrapping="Wrap"
Text="Users will write their problem in here." VerticalAlignment="Top"
Margin="0,231,0,0" Height="414" Width="456" Foreground="White"/>
</Grid>
<Button Name="sendButton" Content="Send your problem" HorizontalAlignment="Stretch"
VerticalAlignment="Top" Margin="10,658,0,0" Grid.Row="1" BorderBrush="#FF996D6D"
Background="#FF081359"/>
Thank you in advance.
You need to replace TextBlock. TextBlock is only used for displaying text, so you can't edit it (eg, drop text onto it). TextBox allows input and will let you drop text into it.
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="10,0,14,0"
RenderTransformOrigin="0.463,0.232">
<TextBox Name="number" HorizontalAlignment="Left" Height="88" Margin="0,98,0,0"
TextWrapping="Wrap" Text="Please enter your phone number" VerticalAlignment="Top"
Width="456"/>
<TextBox Name="bigText" HorizontalAlignment="Left" AllowDrop="True" TextWrapping="Wrap"
Text="Users will write their problem in here." VerticalAlignment="Top"
Margin="0,231,0,0" Height="414" Width="456" Foreground="White"/>
</Grid>
<Button Name="sendButton" Content="Send your problem" HorizontalAlignment="Stretch"
VerticalAlignment="Top" Margin="10,658,0,0" Grid.Row="1" BorderBrush="#FF996D6D"
Background="#FF081359"/>
Related
I'm building a small phonebook application and I'm storing phones in an access database in table called phones whose fields are : FullName,Job,Phone1,Phone2,Notes and SN primary key.
I've set fullname and phone1 to required and set validation rule for fullname to Len([FullName])>3 and validation rule for both phone1 and phone2 to Like "[0-9]*", I also set validation messages for the validation rules.
In a wpf application I've added the access database using visual studio to generate the dataset and tableadapter code, this is MainWindow.xaml:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="253" Width="685">
<Grid Height="206" Width="658">
<Label Content="FullName" Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="Label1" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="78,16,0,0" Name="FullName" VerticalAlignment="Top" Width="185" />
<Label Content="Job" Height="28" HorizontalAlignment="Left" Margin="29,46,0,0" Name="Label2" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="78,46,0,0" Name="Job" VerticalAlignment="Top" Width="185" />
<Label Content="Phone1" Height="28" HorizontalAlignment="Left" Margin="22,75,0,0" Name="Label3" VerticalAlignment="Top" />
<Label Content="Phone2" Height="28" HorizontalAlignment="Left" Margin="269,16,0,0" Name="Label4" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="78,75,0,0" Name="Phone1" VerticalAlignment="Top" Width="110" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="325,21,0,0" Name="Phone2" VerticalAlignment="Top" Width="110" />
<Label Content="Notes" Height="28" HorizontalAlignment="Left" Margin="274,56,0,0" Name="Label5" VerticalAlignment="Top" />
<TextBox Height="95" HorizontalAlignment="Left" Margin="325,60,0,0" Name="Notes" VerticalAlignment="Top" Width="328" AcceptsReturn="True" AcceptsTab="True" />
<Button Content="Save" Height="37" HorizontalAlignment="Left" Margin="274,161,0,0" Name="Button2" VerticalAlignment="Top" Width="135" />
</Grid>
this is save click handler :
private button2_Click(object sender , RoutedEventArgs e)
{
try
{
PhonesDataSetPhonesTableAdapter.Insert(FullName.Text, Job.Text, Phone1.Text, Phone2.Text, Notes.Text);
} catch(OleDbException ex) {
MessageBox.Show(ex.Message);
}
}
the PhonesDataSetPhonesTableAdapter is defined like this :
Global.projectName.PhonesDataSetTableAdapters.PhonesTableAdapter PhonesDataSetPhonesTableAdapter = new Global.projectName.PhonesDataSetTableAdapters.PhonesTableAdapter();
When I launch application and put John as fullname and programmer as job and 2137976 as phone1 number an OleDbException is thrown with the validation message for phone1 which is
your phone number contains letters, it should only contain numbers
but it doesn't contain any letter and when I try the same input through access it accepts it, what's going on here ? and how do I make it work.
The OleDb driver requires a different wildcard character in its Like statement. Instead of * it now wants a % (which is ANSI-92).
If I change in MS Access the validation rule to Like "[0-9]%" I can insert rows with a phonenumber "123" by calling insert on that tableadapter.
The downside of this is that in Access you can no longer insert values as Access now expects the literal character % after a single digit.
If you want both your application and access to work, using the Odbc driver would work.
Here is some background on the issue: Microsoft Jet wildcards: asterisk or percentage sign?
Porting an iOS app and I may be abusing the hub control; but I have a very simple app where I'd like a form to be in a hub section. However it seems like it must be wrapped in a DataTemplate and once it is the form's TextBox controls do not show up in the code behind C# file?
<HubSection x:Uid="HubSection1" Header="SETTINGS"
DataContext="{Binding Groups[2]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
<DataTemplate>
<StackPanel VerticalAlignment="Top" Margin="0,0,20,0">
<TextBlock Text="api base uri" FontSize="21" TextWrapping="NoWrap"/>
<TextBox Name="apiBaseUriTextBox" Margin="0,0,0,10" TextWrapping="Wrap" PlaceholderText="api base uri" VerticalAlignment="Stretch"/>
<TextBlock Text="api key" FontSize="21" TextWrapping="NoWrap" Margin="0,0,0,10"/>
<TextBox Name="apiKeyTextBox" Margin="0,0,0,10" TextWrapping="Wrap" PlaceholderText="api key" VerticalAlignment="Stretch"/>
<TextBlock Text="api secret" FontSize="21" TextWrapping="NoWrap"/>
<TextBox Name="apiSecretTextBox" Margin="0,0,0,10" TextWrapping="Wrap" PlaceholderText="api secret" VerticalAlignment="Stretch"/>
<Button Click="SettingsSaveClickHandler"
Content="Save" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,20,0,0"/>
</StackPanel>
</DataTemplate>
</HubSection>
If you want to put the form directly in the HubSection's DataTemplate then the best way to access the values is by data binding the TextBoxes to properties in your DataContext. The other option would be to crawl the visual tree by calling the VisualTreeHelper from your button's SettingsSaveClickHandler
Another option would be to create your form as a UserControl and then host the completed form in the HubSection's DataTemplate. Again, you can bind it to the DataContext to connect to the underlying data.
I have the following setup
<grid>
<StackPanel>
<ListBox>
<TextBlock> ->Text you see getting cutt off<-
I have tried both just doing listbox.Add(String) and dynamically creating a TextBlock, assigning it text and then adding it to the listbox. Both produce identical results.
The image shows the listbox scrolled down half wayish. It appears the listbox has the correct height but the text inside hits some kind of limit.
UPDATE I changed the listbox to a scroll viewer and also hardcoded the Textblock in. Still same exact results
<Grid x:Name="theGrid" Grid.Row="1" Margin="12,0,10,0">
<StackPanel x:Name="TitlePanel" Grid.Row="0">
<TextBlock Text="Networking Tools" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<StackPanel x:Name="stack">
<TextBlock x:Name="inputIndicator" Margin="12,0,0,0">
<Run Text="Enter IP OR Domain"/>
</TextBlock>
<telerikPrimitives:RadTextBox x:Name="input" Text="google.com" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Grid.Row="1" Height="84" Width="458"/>
<telerikInput:RadListPicker SelectionChanged="picker_SelectionChanged" x:Name="picker" HorizontalAlignment="Left" VerticalAlignment="Top" Width="436"/>
<Button Click="Button_Click" Content="Go" HorizontalAlignment="Left" VerticalAlignment="Top" Width="456"/>
<ScrollViewer HorizontalAlignment="Left" Height="392" Width="Auto" x:Name="list" VerticalAlignment="Top">
<TextBlock Name="content" Height="Auto" Width="Auto"/>
</ScrollViewer>
</StackPanel>
<UI:AdControl ApplicationId="test_client" AdUnitId="Image480_80" Height="80" Width="480"/>
</StackPanel>
<telerikPrimitives:RadBusyIndicator Margin="0,0,0,0" Height="106" Width="116" AnimationStyle="AnimationStyle1" x:Name="busyIndi" />
</Grid>
UI elements in Windows Phone 7 have a maximum renderable height and width of 2048 pixels. Any content that is larger than that gets clipped. The limit is only slightly higher for Windows Phone 8.
You did not mention how much text you are trying to show, but if it is very long, you could be hitting that limit.
There are a few ways you could handle this:
1) Break the text into smaller chunks and add individual TextBlocks to your StackPanel for each chunk.
2) Create a custom control that does the above for you, like this one: http://blogs.msdn.com/b/priozersk/archive/2010/09/08/creating-scrollable-textblock-for-wp7.aspx
3) Use a WebBrowser control instead of a TextBlock, and use its NavigateToString method to put your text in there.
I'm developing a Turing Machine simulator for a class on theory, and I'm trying to change the background color of the input area based upon whether the machine would accept the language (basically, one color over the other depending on if it's valid input).
Since I want to provide a couple example inputs, it needs to be a ComboBox. Since the professor needs to test his own inputs, it must be editable as well. So, here we are.
I've tried setting the ComboBox.Background property both programmatically and using XAML (via the Property editor), and neither work. I have no problem setting ComboBox.Foreground, however.
Here is my XAML:
<Window x:Class="Turing.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Turing Machine Emulator" Height="400" Width="600" Loaded="onload" MinHeight="500" MinWidth="600">
<Grid>
<ComboBox x:Name="drpProblem" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="changeproblem"/>
<Label x:Name="lblDescription" Content="Language Description" Margin="135,7,90,0" VerticalAlignment="Top"/>
<Grid Margin="10,0,10,35" Height="24" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="10*"/>
</Grid.ColumnDefinitions>
<Label x:Name="lblLeft" Content="left" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" Padding="0" Margin="0,0,10,0" FontFamily="Consolas"/>
<Label x:Name="lblRight" Content="right" Grid.Column="2" VerticalContentAlignment="Center" Padding="0" Margin="10,0,0,0" FontFamily="Consolas"/>
<Label x:Name="lblCenter" Content="cur" Grid.Column="1" Height="24" Padding="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Background="#FFC5FFA4" FontFamily="Consolas" FontSize="16"/>
</Grid>
<Button x:Name="btnIterate" Content="Iterate" Margin="10,0,0,64" Height="20" VerticalAlignment="Bottom" Click="btnIterate_Click" HorizontalAlignment="Left" Width="236"/>
<!-- This one right here -->
<ComboBox x:Name="txtInput" Height="23" Margin="10,0,10,89" Text="Input String" VerticalAlignment="Bottom" FontFamily="Consolas" VerticalContentAlignment="Center" TextBoxBase.TextChanged="cboGetInput" BorderBrush="{x:Null}" Foreground="Black" Background="#FF874343" IsEditable="True" />
<TextBox x:Name="txtMs" Height="20" Margin="251,0,172,64" TextWrapping="Wrap" Text="wait (seconds)" VerticalAlignment="Bottom"/>
<Button x:Name="btnAutoRun" Content="AutoRun" Margin="0,0,10,64" Click="btnAutoRun_Click" Height="20" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="157"/>
<TextBox x:Name="txtTM" Margin="10,38,10,142" TextWrapping="Wrap" Text="Language" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" FontFamily="Consolas" FontSize="14"/>
<Button x:Name="btnLoadLang" Content="Load" Margin="10,0,10,117" Height="20" VerticalAlignment="Bottom" Click="changeproblem"/>
<StatusBar Height="30" VerticalAlignment="Bottom">
<TextBlock x:Name="stTXTName" Text="StateName"/>
<Separator/>
<TextBlock x:Name="stTXTDescription" Text="StateDescription"/>
<Separator/>
<TextBlock x:Name="stTXTTransition" Text="NextTransition"/>
<Separator/>
<TextBlock x:Name="stTXTNext" Text="NextState"/>
</StatusBar>
</Grid>
</Window>
and here is the code I'm using to try to change the colors around:
if (TM.AcceptsString(txtInput.Text))
{
txtInput.Background = Brushes.LightGreen;
txtInput.Foreground = Brushes.LightGreen;
}
else
{
txtInput.Background = Brushes.Pink;
txtInput.Foreground = Brushes.Pink;
}
The foreground changes as expected, but the background color never changes from the default White. Am I doing something wrong? Is there some component control within ComboBox that I need to be setting properties for, as I did with TextBoxBase.TextChanged?
Set the FlatStyle attribute of the ComboBox to FlatStyle.Flat. This resolved a similar issue I experienced when the Win 7 Aero theme is turned on: The backcolor of the ComboBox does not show up in the default FlatStyle setting FlatStyle.Standard.
I had a similar issue and was able to resolve it by auto-generating the template for the ComboBox in Visual Studio 2015 (Right Click ComboBox in Design Window -> Edit Template -> Edit a Copy)
In my Windows Phone Application I have a login Page. When I put some text into Pass TextBox, the data should be hide with this symbols: "*". How can I hide info from my custom text box?
<ValidationControl:ValidationControl x:Name="txtPIN" GotFocus="PinTextBox_GotFocus" Margin="0,0,45,0" TextWrapping="Wrap" ValidationContent="Please insert a valid id" LostFocus="PinBoxLostFocus" InputScope="Number" HorizontalAlignment="Right" Width="200" MinWidth="220" MinHeight="80" MaxLength="4" Foreground="Black" Background="#DEFFFFFF" ValidationRule="{StaticResource pinValidationRule}" TextChanged="txtPIN_TextChanged">
<ValidationControl:ValidationControl.ValidationSymbol>
<Image Source="img.png" Height="40" Width="40" />
</ValidationControl:ValidationControl.ValidationSymbol>
</ValidationControl:ValidationControl>
UPDATE
<ValidationControl:ValidationControl x:Name="txtPIN" GotFocus="PinTextBox_GotFocus" Margin="0,0,45,0" TextWrapping="Wrap" ValidationContent="Please insert a valid id" LostFocus="PinBoxLostFocus" InputScope="Password" HorizontalAlignment="Right" Width="200" MinWidth="220" MinHeight="80" MaxLength="4" Foreground="Black" Background="#DEFFFFFF" ValidationRule="{StaticResource pinValidationRule}" TextChanged="txtPIN_TextChanged">
It doesn't work
U can use System.Security.SecureString to keep it encrypted..
System.Security.SecureString is not available on the Windows Phone platform!
Just have a look at the SecureString Class.