小编Dan*_*Dan的帖子

如何从条目中获取文本

我使用创建一个条目

 <Entry Placeholder="Reply..."/>
Run Code Online (Sandbox Code Playgroud)

它位于ListView> ItemTemplate> DataTemplate> ViewCell中

问题是我需要一种方法,一旦用户点击该ViewCell中的提交按钮,它就会获得该单元格中条目的文本.我正在使用Binding来设置值,所以我不知道如何获取文本.

c# xamarin xamarin.forms

6
推荐指数
1
解决办法
144
查看次数

自动调整WebView的大小以适合内容

我正在研究Xamarin.Forms PCL项目,该项目以WebView的形式显示帖子,因此我添加了可点击的内容(例如#标签)。

我遇到的问题是WebView不能适应其内容的大小。WebView不会加载实际的网站,我正在使用以下方法将HTML绑定到ListView中的每个帖子

"<html><p>" + body + "</p></html>"

我尝试研究自定义渲染器,并按照本教程进行操作,最后得到以下代码

我使用的Android

#pragma warning disable CS0618 // Type or member is obsolete
public class CustomWebViewAndroid : WebViewRenderer
{
    static CustomWebView _xwebView = null;
    WebView _webView;            

    class ExtendedWebViewClient : Android.Webkit.WebViewClient
    {
        public override async void OnPageFinished (WebView view, string url)
        {
            if (_xwebView != null) {
                int i = 10;
                while (view.ContentHeight == 0 && i-- > 0) // wait here till content is rendered
                    await System.Threading.Tasks.Task.Delay (100);
                _xwebView.HeightRequest = view.ContentHeight; …
Run Code Online (Sandbox Code Playgroud)

c# xamarin.ios xamarin.android xamarin xamarin.forms

5
推荐指数
2
解决办法
3454
查看次数

在iOS上,框架角落半径不会圆角

我试图围绕堆栈布局的角落,它适用于Android,但在iOS上,它们仍然显示为方形,但它确实显示帧阴影

我的XAML是

<ContentPage.Content>
    <StackLayout BackgroundColor="WHITE">
        <ListView>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout>
                            <Frame CornerRadius="10" Padding="0" Margin="10, 10, 10, 10">
                                <StackLayout>
                                    . . .
                                </StackLayout>
                            </Frame>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>
Run Code Online (Sandbox Code Playgroud)

xaml xamarin.ios xamarin xamarin.forms

4
推荐指数
2
解决办法
3318
查看次数

自定义渲染器的MissingMethodException

加载我的MainPage Visual Studio进入中断模式时出现以下错误

System.MissingMethodException:找不到类型Test.Renderers.PostListViewAndroid的默认构造函数

我更新了我的Custom Renderer类以支持2.5,因为从版本2.5开始,Context已经过时了

我的自定义渲染器是

[assembly: ExportRenderer(typeof(PostListView), typeof(PostListViewAndroid))]
namespace SocialNetwork.Droid.Renderers
 {
public class PostListViewAndroid: ListViewRenderer
{

    public PostListViewAndroid(Context context) : base(context)
    {

    }

    protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
    {
        base.OnElementChanged(e);
        Control.SetSelector(Android.Resource.Color.Transparent);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

PostListView很简单

public class PostListView : ListView
{
}
Run Code Online (Sandbox Code Playgroud)

c# xamarin.android xamarin xamarin.forms

3
推荐指数
1
解决办法
588
查看次数

随机随机排列列表的简单方法

我有一个颜色列表,我希望将它们混洗至少混合一点。

我使用创建列表

 List<Color> colors = new List<Color> ();
 colors.Add(Color.Black);
 colors.Add(Color.White);
 colors.Add(Color.Red);
Run Code Online (Sandbox Code Playgroud)

但是.Shuffle我没有注意到,.Sort但是我认为这不是我所需要的。我搜索了一会儿,但是对于这样一个简单的任务,如果有更简单的方法,我发现所有的方法和其他问题似乎都过于复杂。

我尝试使用

List<Color> colorList = new List<Color>();
public void SetupColors()
    {
        List<Color> colors = new List<Color> ();
        colors.Add(Color.BLACK);
        colors.Add(Color.WHITE);
        colors.Add(Color.RED);
        Random random = new Random();
        int n = colors.Count;

        for (int i = colors.Count; i > 1; i--)
        {
            int rnd = random.Next(i + 1);

            var value = colors[rnd];
            colors[rnd] = colors[i];
            colors[i] = value;
        }
        colorList = colors;
    }

    public List<Message> getMessages()
    {
        List<Message> …
Run Code Online (Sandbox Code Playgroud)

c# xamarin xamarin.forms

3
推荐指数
1
解决办法
4200
查看次数

禁用在 ListView 中选择项目

对于我正在开发的社交网络应用程序,我尝试使用 ListView 显示评论,但我不希望在单击时突出显示它。

我尝试使用

`((ListView)sender).SelectedItem = null;` in a selected event but that still shows it being selected for a second. I need it to never show.
Run Code Online (Sandbox Code Playgroud)

我还尝试将列表视图设置为

IsEnabled="False"

还尝试将它放在查看单元格中,但这会导致按钮和单击事件不起作用。

c# xaml xamarin xamarin.forms

1
推荐指数
1
解决办法
2434
查看次数

在字符串中查找主题标签

我正在 C# 中处理 Xamarin.Forms PCL 项目,并希望检测所有主题标签。

我尝试在空格处拆分并检查单词是否以 # 开头,但问题是如果帖子包含两个空格,例如“Hello #World Test”,它会丢失双空格

string body = "Example string with a #hashtag in it";
        string newbody = "";
        foreach (var word in body.Split(' '))
        {
            if (word.StartsWith("#"))
                newbody += "[" + word + "]";
            newbody += word;
        }
Run Code Online (Sandbox Code Playgroud)

目标输出:

包含 [#hashtag] 的示例字符串

我也只希望它有 AZ az 0-9 和 _ 停在任何其他字符

测试 #H3ll0_W0rld$%Test => 测试 [#H3ll0_W0rld]$%Test

其他堆栈问题尝试检测字符串并提取它,我希望它可以使用它并将其放回字符串中而不会丢失任何方法(例如按某些字符拆分)会丢失的任何内容。

c# xamarin

1
推荐指数
1
解决办法
1187
查看次数

获取应用程序版本并构建

我正在开发 Xamarin.Forms 应用程序,但 iOS 版本似乎无法正确显示。

我将其设置info.plist为版本:0.0 和构建:9,但在应用程序中它显示为版本 1.5.174 和构建 674

[assembly: Xamarin.Forms.Dependency(typeof(SocialNetwork.iOS.Version_iOS))]
namespace SocialNetwork.iOS
{
public class Version_iOS : IAppVersion
{
    public string GetVersion()
    {
        return NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
    }
    public int GetBuild()
    {
        return int.Parse(NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString());
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

IAppVersion 很简单

public interface IAppVersion
{
    string GetVersion();
    int GetBuild();
}
Run Code Online (Sandbox Code Playgroud)

我使用得到的值

public static string AppVersion = DependencyService.Get<IAppVersion>().GetVersion();
    public static int AppBuild = DependencyService.Get<IAppVersion>().GetBuild();
Run Code Online (Sandbox Code Playgroud)

c# xamarin.ios xamarin xamarin.forms

0
推荐指数
1
解决办法
1995
查看次数

标签 统计

xamarin ×8

c# ×7

xamarin.forms ×7

xamarin.ios ×3

xamarin.android ×2

xaml ×2